Þ ¥bonds€¬cell_resultsÞ ŽÙ$f1f89502-0494-11eb-2303-0b79d8bbd13fЦqueued¤logs�§running¦output†¤bodyÙ;frequencies_plot_with_mean (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÕÈtG°persist_js_state·has_pluto_hook_features§cell_idÙ$f1f89502-0494-11eb-2303-0b79d8bbd13f¹depends_on_disabled_cells§runtimeÎ R�µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$95771ce2-0403-11eb-3056-f1dc3a8b7ec3Цqueued¤logs�§running¦output†¤bodyÚh
Note about plotting
Plots.jl has an interesting property: a plot is an object, not an action. Functions like plot, bar, histogram don't draw anything on your screen - they just return a Plots.Plot. This is a struct that contains the description of a plot (what data should be plotted in what way?), not the picture .
So a Pluto cell with a single line, plot(1:10), will show a plot, because the result of the function plot is a Plot object, and Pluto just shows the result of a cell.
Modifying plots
Nice plots are often formed by overlaying multiple plots. In Plots.jl, this is done using the modifying functions : plot!, bar!, vline!, etc. These take an extra (first) argument: a previous plot to modify.
For example, to plot the sin, cos and tan functions in the same view, we do:
function sin_cos_plot()
T = -1.0:0.01:1.0
result = plot(T, sin.(T))
plot!(result, T, cos.(T))
plot!(result, T, tan.(T))
return result
end
💡 This example demonstrates a useful pattern to combine plots:
Create a new plot and store it in a variable
Modify that plot to add more elements
Return the plot
It is recommended that these 3 steps happen within a single cell . This can prevent some strange glitches when re-running cells. There are three ways to group expressions together into a single cell: begin, let and function. More on this later !
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìß;°persist_js_state·has_pluto_hook_features§cell_idÙ$f3f81172-041c-11eb-2b9b-e99b7b9400ed¹depends_on_disabled_cells§runtimeÎ 7ݵpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$8a1d5aea-04ae-11eb-2177-eb37822db4f1Цqueued¤logs�§running¦output†¤bodyÙ&step! (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ö˜Õé°persist_js_state·has_pluto_hook_features§cell_idÙ$8a1d5aea-04ae-11eb-2177-eb37822db4f1¹depends_on_disabled_cells§runtimeÎ F¾µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$4ad11052-042c-11eb-3643-8b2b3e1269bcЦqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ìå$á°persist_js_state·has_pluto_hook_features§cell_idÙ$4ad11052-042c-11eb-3643-8b2b3e1269bc¹depends_on_disabled_cells§runtimeÍêwµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$76d117d4-0403-11eb-05d2-c5ea47d06f43Цqueued¤logs�§running¦output†¤bodyÙ—Exercise 1.3
👉 Write a function frequencies(data) that calculates and returns the frequencies (i.e. probability distribution) of input data.
The input will be an array of integers, with duplicates , and the result will be a dictionary that maps each occured value to its frequency in the data.
For example,
frequencies([7, 8, 9, 7])
should give
Dict(
7 => 0.5,
8 => 0.25,
9 => 0.25
)
As with any probability distribution, it should be normalised to $1$ , in the sense that the total probability should be $1$ .
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌÞxæ°persist_js_state·has_pluto_hook_features§cell_idÙ$771c8f0c-0403-11eb-097e-ab24d0714ad5¹depends_on_disabled_cells§runtimeÎ +µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$3f497394-0a46-11eb-3369-8189905f011cЦqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ì߯?°persist_js_state·has_pluto_hook_features§cell_idÙ$3f497394-0a46-11eb-3369-8189905f011c¹depends_on_disabled_cells§runtimeÎ Qµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$80c2cd88-04b1-11eb-326e-0120a39405eaЦqueued¤logs�§running¦output†¤body…¦prefixÙFNamedTuple{(:S, :I, :R), Tuple{Vector{Any}, Vector{Any}, Vector{Any}}}¨elementsÜ ’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°74f7608fbc82e5a8Ù!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢22ªtext/plain¤type¥Array¬prefix_short ¨objectid°4a237e8966db1388Ù!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢78ªtext/plain¤type¥Array¬prefix_short ¨objectid°557a58c57d88c390Ù!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°9c6166a77619e8d6Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡1ªtext/plain¤type¥Array¬prefix_short ¨objectid°8a29fd2be6e80d7cÙ!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢39ªtext/plain¤type¥Array¬prefix_short ¨objectid°1bd99ae60a4749e2Ù!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢60ªtext/plain¤type¥Array¬prefix_short ¨objectid°b289ef34b7a7f55dÙ!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°43047ddb07568c2dÙ!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid®798a4253872e57Ù!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢29ªtext/plain¤type¥Array¬prefix_short ¨objectid°fea5acb74fde9019Ù!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢71ªtext/plain¤type¥Array¬prefix_short ¨objectid¯e9d318defcd96baÙ!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°fe82a96a4f80c5deÙ!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¢99ªtext/plain¤type¥Array¬prefix_short ¨objectid°1abe72dd88102225Ù!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°d493fa467bbb2cd0Ù!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¡1ªtext/plain¤type¥Array¬prefix_short ¨objectid°b11332b9b4b99f7fÙ!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°e8cbe300eac6e348Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢98ªtext/plain’’¢98ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°d6eb128c80694cc8Ù!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡2ªtext/plain’’¡2ªtext/plain¤more’Íè’¢18ªtext/plain¤type¥Array¬prefix_short ¨objectid°d4a80ea07be345e8Ù!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢82ªtext/plain¤type¥Array¬prefix_short ¨objectid¯789af64e1a68dc4Ù!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°c23381c89836654dÙ!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°8f7d0159718d2d3bÙ!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢29ªtext/plain¤type¥Array¬prefix_short ¨objectid°17873de681a1a74fÙ!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢71ªtext/plain¤type¥Array¬prefix_short ¨objectid°401931b8d2c59547Ù!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°a487f2a57dfb469dÙ!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°7bf7035e4a813425Ù!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢22ªtext/plain¤type¥Array¬prefix_short ¨objectid°cffd6a42728e02e8Ù!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢78ªtext/plain¤type¥Array¬prefix_short ¨objectid°6421d51d1ad6def3Ù!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°31e897714242eecdÙ!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢98ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°b45d7ee0bb4e2e0dÙ!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡2ªtext/plain¤more’Íè’¢23ªtext/plain¤type¥Array¬prefix_short ¨objectid°8d99a0afedc68c1cÙ!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢77ªtext/plain¤type¥Array¬prefix_short ¨objectid°fb7fab284992a22fÙ!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°eb454f42a08693faÙ!application/vnd.pluto.tree+object’ ’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°5bc711d08a21713eÙ!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢29ªtext/plain¤type¥Array¬prefix_short ¨objectid°7d4351874d19f1c7Ù!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢71ªtext/plain¤type¥Array¬prefix_short ¨objectid°afdfd1293252ec9eÙ!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°aca3379257ccdb08Ù!application/vnd.pluto.tree+object’
’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°cc9d09fc6bcd6594Ù!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢23ªtext/plain¤type¥Array¬prefix_short ¨objectid°f7618b57c15665eaÙ!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢77ªtext/plain¤type¥Array¬prefix_short ¨objectid°1f446eef111c1edcÙ!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°150986293ad6897fÙ!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¢99ªtext/plain¤type¥Array¬prefix_short ¨objectid°c5c8b492de24a5d9Ù!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°f9c5c937461ed045Ù!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¡1ªtext/plain¤type¥Array¬prefix_short ¨objectid°715016bd3533713bÙ!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°8a0a568fa36b3c87Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°9322191778d7747bÙ!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢13ªtext/plain¤type¥Array¬prefix_short ¨objectid°1ed845de1043d41eÙ!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢87ªtext/plain¤type¥Array¬prefix_short ¨objectid°597238b78577b69cÙ!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid¯da296ddedcf26bcÙ!application/vnd.pluto.tree+object’
’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°695dc8d0a54fefb6Ù!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢28ªtext/plain¤type¥Array¬prefix_short ¨objectid°c118f5f854c64adcÙ!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢72ªtext/plain¤type¥Array¬prefix_short ¨objectid°cf3b844ef10ac5b9Ù!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°71f70baef54a6331Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢98ªtext/plain’’¢98ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°768bbbcb3fab308bÙ!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡2ªtext/plain’’¡2ªtext/plain¤more’Íè’¢30ªtext/plain¤type¥Array¬prefix_short ¨objectid¯f6e51dff1705d8aÙ!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢70ªtext/plain¤type¥Array¬prefix_short ¨objectid°992f2b8904f211ceÙ!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°52c6f11510796fb2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°b90e0b39c4afd24bÙ!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢23ªtext/plain¤type¥Array¬prefix_short ¨objectid°e5ec17829e6bebb0Ù!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢77ªtext/plain¤type¥Array¬prefix_short ¨objectid°cf8bdaf0f1ab7379Ù!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°b79bb163c086a377Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¢99ªtext/plain¤type¥Array¬prefix_short ¨objectid¯58c04c25dac5ca7Ù!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°a58f714b1db336caÙ!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¡1ªtext/plain¤type¥Array¬prefix_short ¨objectid°1387cc5179a3edf5Ù!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°a8ebe5659ead70b2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢97ªtext/plain’’¢97ªtext/plain’’¢97ªtext/plain’’¢97ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°1db2bfb60df9d58aÙ!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡3ªtext/plain’’¡3ªtext/plain’’¡3ªtext/plain’’¡3ªtext/plain¤more’Íè’¢19ªtext/plain¤type¥Array¬prefix_short ¨objectid°3e0102814e965bf0Ù!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢81ªtext/plain¤type¥Array¬prefix_short ¨objectid°2c2b71e52aeb3bd8Ù!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°bbb28a787626979bÙ!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°1abdb834080fc962Ù!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢38ªtext/plain¤type¥Array¬prefix_short ¨objectid°76b047f73ff4e9bbÙ!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢62ªtext/plain¤type¥Array¬prefix_short ¨objectid°2ec626d73020adacÙ!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°55b0e5ad3436778eÙ!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°d35639a4f940cf25Ù!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢21ªtext/plain¤type¥Array¬prefix_short ¨objectid°43dd20935a4e9dd4Ù!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢79ªtext/plain¤type¥Array¬prefix_short ¨objectid¯327a5ccd8e31a9cÙ!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°beededd80fcaf4c9Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’…¦prefix£Any¨elements—’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°c72bfa1560ebc62aÙ!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements—’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain¤more’Íè’¢43ªtext/plain¤type¥Array¬prefix_short ¨objectid°e963e0b6a55b8f4cÙ!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements—’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain¤more’Íè’¢57ªtext/plain¤type¥Array¬prefix_short ¨objectid°7ae75f46c8629256Ù!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°1def7af6d6cb6454Ù!application/vnd.pluto.tree+object¤type¥Array¬prefix_short ¨objectid°731197afd9a5259a¤mimeÙ!application/vnd.pluto.tree+object¬rootassignee«simulations²last_run_timestampËAÚ ×R¦±°persist_js_state·has_pluto_hook_features§cell_idÙ$80c2cd88-04b1-11eb-326e-0120a39405ea¹depends_on_disabled_cells§runtimeÎÀ¶òµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$105d347e-041c-11eb-2fc8-1d9e5eda2be0Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÌÞÃ3°persist_js_state·has_pluto_hook_features§cell_idÙ$105d347e-041c-11eb-2fc8-1d9e5eda2be0¹depends_on_disabled_cells§runtimeÍ9صpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$2c62b4ae-04b3-11eb-0080-a1035a7e31a2Цqueued¤logs�§running¦output†¤bodyƒ¨elements“’¡S’…¦prefix£Any¨elements›’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’’¢99ªtext/plain’ ’¢99ªtext/plain¤more’Íè’¢99ªtext/plain¤type¥Array¬prefix_short ¨objectid°6a449c1bc8b6833eÙ!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements›’’¡1ªtext/plain’’¡1ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’ ’¡0ªtext/plain¤more’Íè’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°f231b62ad890b61aÙ!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements›’’¡0ªtext/plain’’¡0ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’ ’¡1ªtext/plain¤more’Íè’¡1ªtext/plain¤type¥Array¬prefix_short ¨objectid°1128e60e967f17d1Ù!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°d13019d3659c3ca1¤mimeÙ!application/vnd.pluto.tree+object¬rootassigneeÀ²last_run_timestampËAÚ Öôg°persist_js_state·has_pluto_hook_features§cell_idÙ$2c62b4ae-04b3-11eb-0080-a1035a7e31a2¹depends_on_disabled_cells§runtimeÎ T8µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$6db6c894-0415-11eb-305a-c75b119d89e9Цqueued¤logs�§running¦output†¤bodyÚßWe should always be aware of special cases (sometimes called "boundary conditions"). Make sure not to run the code with $p=0$ ! What would happen in that case? Your code should check for this and throw an ArgumentError as follows:
throw(ArgumentError("..."))
with a suitable error message.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌÝÙõ°persist_js_state·has_pluto_hook_features§cell_idÙ$6db6c894-0415-11eb-305a-c75b119d89e9¹depends_on_disabled_cells§runtimeÎ $Uµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$77db111e-0403-11eb-2dea-4b42ceed65d6Цqueued¤logs�§running¦output†¤bodyÚlExercise 1.6
👉 Use $N = 10,000$ to calculate the mean time $\langle \tau(p) \rangle$ to recover as a function of $p$ between $0.001$ and $1$ (say). Plot this relationship.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìà!°persist_js_state·has_pluto_hook_features§cell_idÙ$77db111e-0403-11eb-2dea-4b42ceed65d6¹depends_on_disabled_cells§runtimeÎ ¶µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$6d480cf0-0425-11eb-18a9-1737455371d7Цqueued¤logs�§running¦output†¤bodyÙ0generate_agents (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ö]R°persist_js_state·has_pluto_hook_features§cell_idÙ$6d480cf0-0425-11eb-18a9-1737455371d7¹depends_on_disabled_cells§runtimeÎ ¬àµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$287ee7aa-0435-11eb-0ca3-951dbbe69404Цqueued¤logs�§running¦output†¤bodyÙ4sir_mean_error_plot (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ×«ñ°persist_js_state·has_pluto_hook_features§cell_idÙ$287ee7aa-0435-11eb-0ca3-951dbbe69404¹depends_on_disabled_cells§runtimeÎ ‘Ûµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$3d88c056-0414-11eb-0025-05d3aff1588bЦqueued¤logs�§running¦output†¤bodyÙ)correct (generic function with 2 methods)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ×ø£‡°persist_js_state·has_pluto_hook_features§cell_idÙ$3d88c056-0414-11eb-0025-05d3aff1588b¹depends_on_disabled_cells§runtimeÎ
ôŸµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$03a85970-0403-11eb-334a-812b59c0905bЦqueued¤logs�§running¦output†¤bodyÙmSubmission by: Jazzy Doe (jazz@mit.edu)
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ñà?«°persist_js_state·has_pluto_hook_features§cell_idÙ$03a85970-0403-11eb-334a-812b59c0905b¹depends_on_disabled_cells§runtimeÎ�7µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$6d906d0c-0415-11eb-0c1c-b5c0aca841dbЦqueued¤logs�§running¦output†¤bodyÙéHint
Remember to always re-use work you have done previously: in this case you should re-use the function bernoulli.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ×¾l°persist_js_state·has_pluto_hook_features§cell_idÙ$6d906d0c-0415-11eb-0c1c-b5c0aca841db¹depends_on_disabled_cells§runtimeÎ�xDµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$866299e8-0403-11eb-085d-2b93459cc141Цqueued¤logs�§running¦output†¤bodyٸ👉 We will also need functions is_susceptible and is_infected that check if a given agent is in those respective states.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìáaú°persist_js_state·has_pluto_hook_features§cell_idÙ$866299e8-0403-11eb-085d-2b93459cc141¹depends_on_disabled_cells§runtimeÎ n5µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$461586dc-0414-11eb-00f3-4984b57bfac5Цqueued¤logs�§running¦output†¤bodyÙ'almost (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ×Ê_c°persist_js_state·has_pluto_hook_features§cell_idÙ$461586dc-0414-11eb-00f3-4984b57bfac5¹depends_on_disabled_cells§runtimeÎ ÃBµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$c5156c72-04af-11eb-1106-b13969b036caЦqueued¤logs�§running¦output†¤bodyÛ ª¥
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ×0ª°persist_js_state·has_pluto_hook_features§cell_idÙ$c5156c72-04af-11eb-1106-b13969b036ca¹depends_on_disabled_cells§runtimeÎtŠÕµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$c4a8694a-04d4-11eb-1eef-c9e037e6b21fЦqueued¤logs�§running¦output†¤bodyÙ¥Here we go!
Replace missing with your answer.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Øi°persist_js_state·has_pluto_hook_features§cell_idÙ$c4a8694a-04d4-11eb-1eef-c9e037e6b21f¹depends_on_disabled_cells§runtimeÎ …&µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$1491a078-04aa-11eb-0106-19a3cf1e94b0Цqueued¤logs�§running¦output†¤bodyÙÁGot it!
Your function treats the infectious agent case correctly!
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ø/ê°persist_js_state·has_pluto_hook_features§cell_idÙ$1491a078-04aa-11eb-0106-19a3cf1e94b0¹depends_on_disabled_cells§runtimeÎ Äʵpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$c5c7cb86-041b-11eb-3360-45463105f3c9Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÌÞVó°persist_js_state·has_pluto_hook_features§cell_idÙ$c5c7cb86-041b-11eb-3360-45463105f3c9¹depends_on_disabled_cells§runtimeÍ;6µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$01341648-0403-11eb-2212-db450c299f35Цqueued¤logs�§running¦output†¤bodyÙB¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌÜx6°persist_js_state·has_pluto_hook_features§cell_idÙ$01341648-0403-11eb-2212-db450c299f35¹depends_on_disabled_cells§runtimeÎ cµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$d8797684-0414-11eb-1869-5b1e2c469011Цqueued¤logs�§running¦output†¤bodyÙ*bernoulli (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ñ°persist_js_state·has_pluto_hook_features§cell_idÙ$d8797684-0414-11eb-1869-5b1e2c469011¹depends_on_disabled_cells§runtimeÎ òϵpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$48a16c42-0414-11eb-0e0c-bf52bbb0f618Цqueued¤logs�§running¦output†¤bodyÙ%hint (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ×º>´°persist_js_state·has_pluto_hook_features§cell_idÙ$48a16c42-0414-11eb-0e0c-bf52bbb0f618¹depends_on_disabled_cells§runtimeÎ [6µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$98beb336-0425-11eb-3886-4f8cfd210288Цqueued¤logs�§running¦output†¤bodyÙ,set_status! (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ö;ëò°persist_js_state·has_pluto_hook_features§cell_idÙ$98beb336-0425-11eb-3886-4f8cfd210288¹depends_on_disabled_cells§runtimeÎ ’�µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$bb63f3cc-042f-11eb-04ff-a128aec3c378Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ì߀„°persist_js_state·has_pluto_hook_features§cell_idÙ$bb63f3cc-042f-11eb-04ff-a128aec3c378¹depends_on_disabled_cells§runtimeÍꟵpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$61c00724-0403-11eb-228d-17c11670e5d1Цqueued¤logs�§running¦output†¤bodyÚ™Exercise 4: Reinfection
In this exercise we will re-use our simulation infrastructure to study the dynamics of a different type of infection: there is no immunity, and hence no "recovery" rather, susceptible individuals may now be re-infected
Exercise 4.1
👉 Make a new infection type Reinfection. This has the same two fields as InfectionRecovery (p_infection and p_recovery). However, "recovery" now means "becomes susceptible again", instead of "moves to the R class.
This new type Reinfection should also be a subtype of AbstractInfection. This allows us to reuse our previous functions, which are defined for the abstract supertype.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌåHù°persist_js_state·has_pluto_hook_features§cell_idÙ$61c00724-0403-11eb-228d-17c11670e5d1¹depends_on_disabled_cells§runtimeÎ
µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9cf9080a-04b1-11eb-12a0-17013f2d37f5Цqueued¤logs�§running¦output†¤bodyÚ,👉 Calculate the mean number of infectious agents of our simulations for each time step. Add it to the plot using a heavier line (lw=3 for "linewidth") by modifying the cell above.
Check the answer yourself: does your curve follow the average trend?
Hint
This exercise requires some creative juggling with arrays, anonymous functions, maps, or whatever you see fit!
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ×¿
(°persist_js_state·has_pluto_hook_features§cell_idÙ$9cf9080a-04b1-11eb-12a0-17013f2d37f5¹depends_on_disabled_cells§runtimeÎ ñµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8Цqueued¤logs�§running¦output†¤body…¦prefix¥Int64¨elementsÜ ’’¡5ªtext/plain’’¡1ªtext/plain’’¡9ªtext/plain’’¡2ªtext/plain’’¡4ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¢13ªtext/plain’ ’¡4ªtext/plain’
’¡3ªtext/plain’’¡3ªtext/plain’’¡7ªtext/plain’
’¡9ªtext/plain’’¡2ªtext/plain’’¡5ªtext/plain’’¡6ªtext/plain’’¡1ªtext/plain’’¢16ªtext/plain’’¡1ªtext/plain’’¢10ªtext/plain¤more’Í'’¡1ªtext/plain’Í'’¡2ªtext/plain’Í' ’¡6ªtext/plain’Í'
’¡6ªtext/plain’Í'’¡3ªtext/plain’Í'’¡5ªtext/plain’Í'
’¡1ªtext/plain’Í'’¢11ªtext/plain’Í'’¡8ªtext/plain’Í'’¡2ªtext/plain¤type¥Array¬prefix_short ¨objectid°3cf54089ffc203ea¤mimeÙ!application/vnd.pluto.tree+object¬rootassignee°large_experiment²last_run_timestampËAÚ ÒU¤ß°persist_js_state·has_pluto_hook_features§cell_idÙ$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8¹depends_on_disabled_cells§runtimeÎ „”µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$61789646-0403-11eb-0042-f3b8308f11baЦqueued¤logs�§running¦output†¤bodyÚ3Exercise 2: Agent-based model for an epidemic outbreak – types
In this and the following exercises we will develop a simple stochastic model for combined infection and recovery in a population, which may exhibit an epidemic outbreak (i.e. a large spike in the number of infectious people). The population is well mixed , i.e. everyone is in contact with everyone else. [An example of this would be a small school or university in which people are constantly moving around and interacting with each other.]
The model is an individual-based or agent-based model: we explicitly keep track of each individual, or agent , in the population and their infection status. For the moment we will not keep track of their position in space; we will just assume that there is some mechanism, not included in the model, by which they interact with other individuals.
Exercise 2.1
Each agent will have its own internal state , modelling its infection status, namely "susceptible", "infectious" or "recovered". We would like to code these as values S, I and R, respectively. One way to do this is using an enumerated type or enum . Variables of this type can take only a pre-defined set of values; the Julia syntax is as follows:
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌàP‹°persist_js_state·has_pluto_hook_features§cell_idÙ$61789646-0403-11eb-0042-f3b8308f11ba¹depends_on_disabled_cells§runtimeÎ
7µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$39dffa3c-0414-11eb-0197-e72b299e9c63Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ø8>S°persist_js_state·has_pluto_hook_features§cell_idÙ$39dffa3c-0414-11eb-0197-e72b299e9c63¹depends_on_disabled_cells§runtimeÍhKµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$5950b37e-0a46-11eb-3480-d5520013692eЦqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÌßìJ°persist_js_state·has_pluto_hook_features§cell_idÙ$5950b37e-0a46-11eb-3480-d5520013692e¹depends_on_disabled_cells§runtimeÎ ‘µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$cdaade9c-0416-11eb-0550-7b5b3d33e240Цqueued¤logs�§running¦output†¤bodyÙ.do_experiment (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ò
úL°persist_js_state·has_pluto_hook_features§cell_idÙ$cdaade9c-0416-11eb-0550-7b5b3d33e240¹depends_on_disabled_cells§runtimeÎ Á˵published_object_keys�¸depends_on_skipped_cells§erroredÂÙ$88c53208-041d-11eb-3b1e-31b57ba99f05Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ìà–…°persist_js_state·has_pluto_hook_features§cell_idÙ$88c53208-041d-11eb-3b1e-31b57ba99f05¹depends_on_disabled_cells§runtimeÍèOµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272Цqueued¤logs�§running¦output†¤bodyÙÀGot it!
Your function treats the recovered agent case correctly!
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ø3Ñ9°persist_js_state·has_pluto_hook_features§cell_idÙ$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272¹depends_on_disabled_cells§runtimeÎ ¶Nµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$887d27fc-04bc-11eb-0ab9-eb95ef9607f8Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÌãÅÚ°persist_js_state·has_pluto_hook_features§cell_idÙ$887d27fc-04bc-11eb-0ab9-eb95ef9607f8¹depends_on_disabled_cells§runtimeÍ:úµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$d57c6a5a-041b-11eb-3ab4-774a2d45a891Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ìݽo°persist_js_state·has_pluto_hook_features§cell_idÙ$d57c6a5a-041b-11eb-3ab4-774a2d45a891¹depends_on_disabled_cells§runtimeÍ=5µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$12cc2940-0403-11eb-19a7-bb570de58f6fЦqueued¤logs‘ˆ¤lineÿ£msg’Ù@[32m[1m Activating[22m[39m new project at `/tmp/jl_SHw1SH`
ªtext/plain§cell_idÙ$12cc2940-0403-11eb-19a7-bb570de58f6f¦kwargs�¢id´PlutoRunner_d1acb81e¤fileÙP/home/runner/.julia/packages/Pluto/6smog/src/runner/PlutoRunner/src/io/stdout.jl¥group¦stdout¥level®LogLevel(-555)§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ï&Ȱpersist_js_state·has_pluto_hook_features§cell_idÙ$12cc2940-0403-11eb-19a7-bb570de58f6f¹depends_on_disabled_cells§runtimeÎg]jµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$76f62d64-0403-11eb-27e2-3de58366b619Цqueued¤logs�§running¦output†¤bodyÙçExercise 1.2
👉 Write a function do_experiment(p, N) that runs the function recovery_time N times and collects the results into a vector.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌÞo°persist_js_state·has_pluto_hook_features§cell_idÙ$76f62d64-0403-11eb-27e2-3de58366b619¹depends_on_disabled_cells§runtimeÎ æ<µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$860790fc-0403-11eb-2f2e-355f77dcc7afЦqueued¤logs�§running¦output†¤bodyÚLExercise 2.2
For each agent we want to keep track of its infection status and the number of other agents that it infects during the simulation. A good solution for this is to define a new type Agent to hold all of the information for one agent, as follows:
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌàÊ2°persist_js_state·has_pluto_hook_features§cell_idÙ$860790fc-0403-11eb-2f2e-355f77dcc7af¹depends_on_disabled_cells§runtimeÎ çßµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$b21475c6-04ac-11eb-1366-f3b5e967402dЦqueued¤logs�§running¦output†¤bodyÚPlay around with the test case below to test your function! Try changing the definitions of agent, source and infection. Since we are working with randomness, you might want to run the cell multiple times.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìâr°persist_js_state·has_pluto_hook_features§cell_idÙ$b21475c6-04ac-11eb-1366-f3b5e967402d¹depends_on_disabled_cells§runtimeÎ ‚ʵpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$823364ce-041c-11eb-2467-7ffa4f751527Цqueued¤logs�§running¦output†¤bodyÙ>frequencies_plot_with_maximum (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Õ™Í³°persist_js_state·has_pluto_hook_features§cell_idÙ$823364ce-041c-11eb-2467-7ffa4f751527¹depends_on_disabled_cells§runtimeÎ ¶_µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$619c8a10-0403-11eb-2e89-8b0974fb01d0Цqueued¤logs�§running¦output†¤bodyÚÛExercise 3: Agent-based model for an epidemic outbreak – Monte Carlo simulation
In this exercise we will build on Exercise 2 to write a Monte Carlo simulation of how an infection propagates in a population.
Make sure to re-use the functions that we have already written, and introduce new ones if they are helpful! Short functions make it easier to understand what the function does and build up new functionality piece by piece.
You should not use any global variables inside the functions: Each function must accept as arguments all the information it requires to carry out its task. You need to think carefully about what the information each function requires.
Exercise 3.1
👉 Write a function step! that takes a vector of Agents and an infection of type InfectionRecovery. It implements a single step of the infection dynamics as follows:
Choose two random agents: an agent and a source.
Apply interact!(agent, source, infection).
Return agents.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìâš®°persist_js_state·has_pluto_hook_features§cell_idÙ$619c8a10-0403-11eb-2e89-8b0974fb01d0¹depends_on_disabled_cells§runtimeÎ Bµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$38b1aa5a-04cf-11eb-11a2-930741fc9076Цqueued¤logs�§running¦output†¤bodyÙ3repeat_simulations (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ×;;%°persist_js_state·has_pluto_hook_features§cell_idÙ$38b1aa5a-04cf-11eb-11a2-930741fc9076¹depends_on_disabled_cells§runtimeÎ âµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$8dd97820-04a5-11eb-36c0-8f92d4b859a8Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ìå[§°persist_js_state·has_pluto_hook_features§cell_idÙ$8dd97820-04a5-11eb-36c0-8f92d4b859a8¹depends_on_disabled_cells§runtimeÍìlµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$df8547b4-0400-11eb-07c6-fb370b61c2b6Цqueued¤logs�§running¦output†¤bodyÚPExercise 1: Modelling recovery
In this exercise we will investigate a simple stochastic (probabilistic) model of recovery from an infection and the time $\tau$ needed to recover. Although this model can be easily studied analytically using probability theory, we will instead use computational methods. (If you know about this distribution already, try to ignore what you know about it!)
In this model, an individual who is infected has a constant probability $p$ to recover each day. If they recover on day $n$ then $\tau$ takes the value $n$ . Each time we run a new experiment $\tau$ will take on different values, so $\tau$ is a (discrete) random variable. We thus need to study statistical properties of $\tau$ , such as its mean and its probability distribution.
Exercise 1.1 - Probability distributions
👉 Define the function bernoulli(p), which returns true with probability $p$ and false with probability $(1 - p)$ .
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌÜû×°persist_js_state·has_pluto_hook_features§cell_idÙ$df8547b4-0400-11eb-07c6-fb370b61c2b6¹depends_on_disabled_cells§runtimeÎ |›µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$1d3356c4-0403-11eb-0f48-01b5eb14a585Цqueued¤logs�§running¦output†¤bodyÙÔVIDEO
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌÜØ²°persist_js_state·has_pluto_hook_features§cell_idÙ$1d3356c4-0403-11eb-0f48-01b5eb14a585¹depends_on_disabled_cells§runtimeÎ ë<µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$82f2580a-04c8-11eb-1eea-bdb4e50eee3bЦqueued¤logs�§running¦output†¤body‚£msgÚÍMethodError: no method matching Main.workspace#4.Agent()
[0mClosest candidates are:
[0m Main.workspace#4.Agent([91m::Main.workspace#4.InfectionStatus[39m, [91m::Int64[39m) at ~/work/disorganised-mess/disorganised-mess/hw4 some solutions.jl#==#ae4ac4b4-041f-11eb-14f5-1bcde35d18f2:2
[0m Main.workspace#4.Agent([91m::Any[39m, [91m::Any[39m) at ~/work/disorganised-mess/disorganised-mess/hw4 some solutions.jl#==#ae4ac4b4-041f-11eb-14f5-1bcde35d18f2:2ªstacktrace‘Œªcall_short¯top-level scope§inlinedãurlÀ¤pathÙs/home/runner/work/disorganised-mess/disorganised-mess/hw4 some solutions.jl#==#82f2580a-04c8-11eb-1eea-bdb4e50eee3b®source_packageÀ¤call¯top-level scopeªlinfo_type§Nothing¤line¤fileÙ=hw4 some solutions.jl#==#82f2580a-04c8-11eb-1eea-bdb4e50eee3b¤func»##function_wrapped_cell#359parent_moduleÀ¦from_c¤mimeÙ'application/vnd.pluto.stacktrace+object¬rootassigneeÀ²last_run_timestampËAÚ Ö0+c°persist_js_state·has_pluto_hook_features§cell_idÙ$82f2580a-04c8-11eb-1eea-bdb4e50eee3b¹depends_on_disabled_cells§runtimeÀµpublished_object_keys�¸depends_on_skipped_cells§erroredÃÙ$86d98d0a-0403-11eb-215b-c58ad721a90bЦqueued¤logs�§running¦output†¤bodyÚ�We will also need types representing different infections.
Let's define an (immutable) struct called InfectionRecovery with parameters p_infection and p_recovery. We will make it a subtype of an abstract AbstractInfection type, because we will define more infection types later.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìá莰persist_js_state·has_pluto_hook_features§cell_idÙ$86d98d0a-0403-11eb-215b-c58ad721a90b¹depends_on_disabled_cells§runtimeÎ Zæµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$dc784864-0430-11eb-1478-d1153e017310Цqueued¤logs�§running¦output†¤bodyÚ‡The frequencies dictionary is difficult to interpret on its own, so instead, we will plot it, i.e. plot $P(\tau = n)$ against $n$ , where $n$ is the recovery time.
Plots.jl comes with a function bar, which does exactly what we want:
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌÞøf°persist_js_state·has_pluto_hook_features§cell_idÙ$dc784864-0430-11eb-1478-d1153e017310¹depends_on_disabled_cells§runtimeÎ ÊHµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$3f5e0af8-0414-11eb-34a7-a71e7aaf6443Цqueued¤logs�§running¦output†¤body…¦prefix«Markdown.MD¨elements›’’Ù2©text/html’’Ù1©text/html’’Ù.©text/html’’Ù+©text/html’’Ù3©text/html’’Ù2©text/html’’Ù3©text/html’’Ù1©text/html’ ’Ù0©text/html’
’ÙAYou got the right answer!
©text/html’’ÙJLet's move on to the next section.
©text/html¤type¥Array¬prefix_short ¨objectid°641ac141a725789c¤mimeÙ!application/vnd.pluto.tree+object¬rootassignee¤yays²last_run_timestampËAÚ ×í4¨°persist_js_state·has_pluto_hook_features§cell_idÙ$3f5e0af8-0414-11eb-34a7-a71e7aaf6443¹depends_on_disabled_cells§runtimeÎ ¥/ŵpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$3c0528a0-0414-11eb-2f68-a5657ab9e73dЦqueued¤logs�§running¦output†¤bodyÙ,not_defined (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Øõذpersist_js_state·has_pluto_hook_features§cell_idÙ$3c0528a0-0414-11eb-2f68-a5657ab9e73d¹depends_on_disabled_cells§runtimeÎ ¤rµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$7335de44-042f-11eb-2873-8bceef722432Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ìà°persist_js_state·has_pluto_hook_features§cell_idÙ$7335de44-042f-11eb-2873-8bceef722432¹depends_on_disabled_cells§runtimeÎ $lµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$406aabea-04a5-11eb-06b8-312879457c42Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÌâX6°persist_js_state·has_pluto_hook_features§cell_idÙ$406aabea-04a5-11eb-06b8-312879457c42¹depends_on_disabled_cells§runtimeÍ<0µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$c61f35ea-04d6-11eb-2503-17a79f8d0298Цqueued¤logs�§running¦output†¤bodyÙ‚¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ø@°persist_js_state·has_pluto_hook_features§cell_idÙ$c61f35ea-04d6-11eb-2503-17a79f8d0298¹depends_on_disabled_cells§runtimeÎ YDµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9cd2bb00-04b1-11eb-1d83-a703907141a7Цqueued¤logs�§running¦output†¤bodyÛ
È®
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ×ZË÷°persist_js_state·has_pluto_hook_features§cell_idÙ$9cd2bb00-04b1-11eb-1d83-a703907141a7¹depends_on_disabled_cells§runtimeÎ]´öµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$8a28c56e-04b4-11eb-279c-3b4dfb2a9f9bЦqueued¤logs�§running¦output†¤bodyÚo‹
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÕŽ¤@°persist_js_state·has_pluto_hook_features§cell_idÙ$8a28c56e-04b4-11eb-279c-3b4dfb2a9f9b¹depends_on_disabled_cells§runtimeÎý7MÚµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$8631a536-0403-11eb-0379-bb2e56927727Цqueued¤logs�§running¦output†¤bodyÚ�Exercise 2.3
👉 Write functions set_status!(a) and set_num_infected!(a) which modify the respective fields of an Agent. Check that they work. [Note the bang ("!") at the end of the function names to signify that these functions modify their argument.]
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌáIo°persist_js_state·has_pluto_hook_features§cell_idÙ$8631a536-0403-11eb-0379-bb2e56927727¹depends_on_disabled_cells§runtimeÎ ÏJµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9a13b17c-0403-11eb-024f-9b37e95e211bЦqueued¤logs�§running¦output†¤bodyÚExercise 4.2
👉 Run the simulation 20 times and plot $I$ as a function of time for each one, together with the mean over the 20 simulations (as you did in the previous exercises).
Note that you should be able to re-use the sweep! and simulation functions , since those should be sufficiently generic to work with the new step! function! (Modify them if they are not.)
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìå”u°persist_js_state·has_pluto_hook_features§cell_idÙ$9a13b17c-0403-11eb-024f-9b37e95e211b¹depends_on_disabled_cells§runtimeÎ trµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$b92f1cec-04ae-11eb-0072-3535d1118494Цqueued¤logs�§running¦output†¤bodyƒ¨elements“’¡S’…¦prefix£Any¨elements›’’¡2ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’’¡0ªtext/plain’ ’¡0ªtext/plain¤more’’¡0ªtext/plain¤type¥Array¬prefix_short ¨objectid°761d83d545bbd707Ù!application/vnd.pluto.tree+object’¡I’…¦prefix£Any¨elements›’’¡1ªtext/plain’’¡3ªtext/plain’’¡2ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’’¡1ªtext/plain’ ’¡1ªtext/plain¤more’’¡1ªtext/plain¤type¥Array¬prefix_short ¨objectid¯198db94dcb28194Ù!application/vnd.pluto.tree+object’¡R’…¦prefix£Any¨elements›’’¡0ªtext/plain’’¡0ªtext/plain’’¡1ªtext/plain’’¡2ªtext/plain’’¡2ªtext/plain’’¡2ªtext/plain’’¡2ªtext/plain’’¡2ªtext/plain’ ’¡2ªtext/plain¤more’’¡2ªtext/plain¤type¥Array¬prefix_short ¨objectid°b9945178cca96c89Ù!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°b99b34bcb4905a68¤mimeÙ!application/vnd.pluto.tree+object¬rootassigneeÀ²last_run_timestampËAÚ ÖÁM¾°persist_js_state·has_pluto_hook_features§cell_idÙ$b92f1cec-04ae-11eb-0072-3535d1118494¹depends_on_disabled_cells§runtimeÍaõpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$5ef5813a-0a46-11eb-00d3-01ec142e3897Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÌßÙM°persist_js_state·has_pluto_hook_features§cell_idÙ$5ef5813a-0a46-11eb-00d3-01ec142e3897¹depends_on_disabled_cells§runtimeÎ (µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9a377b32-0403-11eb-2799-e7e59caa6a45Цqueued¤logs�§running¦output†¤bodyÙæðŸ‘‰ Run the new simulation and draw $I$ (averaged over runs) as a function of time. Is the behaviour qualitatively the same or different? Describe what you see.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìå¿8°persist_js_state·has_pluto_hook_features§cell_idÙ$9a377b32-0403-11eb-2799-e7e59caa6a45¹depends_on_disabled_cells§runtimeÎ ±µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$778ec25c-0403-11eb-3146-1d11c294bb1fЦqueued¤logs�§running¦output†¤bodyÙ²Exercise 1.5
👉 What shape does the distribution seem to have? Can you verify that by adding a second plot with the expected shape?
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ì߲Ѱpersist_js_state·has_pluto_hook_features§cell_idÙ$778ec25c-0403-11eb-3146-1d11c294bb1f¹depends_on_disabled_cells§runtimeΠŵpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9611ca24-0403-11eb-3582-b7e3bb243e62Цqueued¤logs�§running¦output†¤bodyÙùExercise 3.3
👉 Plot the probability distribution of num_infected. Does it have a recognisable shape? (Feel free to increase the number of agents in order to get better statistics.)
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìää°°persist_js_state·has_pluto_hook_features§cell_idÙ$9611ca24-0403-11eb-3582-b7e3bb243e62¹depends_on_disabled_cells§runtimeÎ ËYµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$26f84600-041d-11eb-1856-b12a3e5c1dc7Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÕûGk°persist_js_state·has_pluto_hook_features§cell_idÙ$26f84600-041d-11eb-1856-b12a3e5c1dc7¹depends_on_disabled_cells§runtimeÎX;âµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$1ca7a8c2-041a-11eb-146a-15b8cdeaea72Цqueued¤logs�§running¦output†¤body…¦prefix®Dict{Any, Any}¨elements•’’¡5ªtext/plain’£0.1ªtext/plain’’¡4ªtext/plain’¤0.05ªtext/plain’’¡2ªtext/plain’£0.1ªtext/plain’’¡3ªtext/plain’£0.2ªtext/plain’’¡1ªtext/plain’¤0.55ªtext/plain¤type¤Dict¬prefix_short¤Dict¨objectid°44cd86ee795993f0¤mimeÙ!application/vnd.pluto.tree+object¬rootassigneeÀ²last_run_timestampËAÚ ÒO]¼°persist_js_state·has_pluto_hook_features§cell_idÙ$1ca7a8c2-041a-11eb-146a-15b8cdeaea72¹depends_on_disabled_cells§runtimeÎå>µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$190deebc-0424-11eb-19fe-615997093e14Цqueued¤logs�§running¦output†¤bodyÚÈ👉 For convenience, define a new constructor (i.e. a new method for the function) that takes no arguments and creates an Agent with status S and number infected 0, by calling one of the default constructors that Julia creates. This new method lives outside (not inside) the definition of the struct. (It is called an outer constructor .)
(In Pluto, multiple methods for the same function need to be combined in a single cell using a begin end block.)
Let's check that the new method works correctly. How many methods does the constructor have now?
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìá.0°persist_js_state·has_pluto_hook_features§cell_idÙ$190deebc-0424-11eb-19fe-615997093e14¹depends_on_disabled_cells§runtimeÎ [‹µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$1a654bdc-0421-11eb-2c38-7d35060e2565Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ö{'°persist_js_state·has_pluto_hook_features§cell_idÙ$1a654bdc-0421-11eb-2c38-7d35060e2565¹depends_on_disabled_cells§runtimeÎ K½µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$41cefa68-0414-11eb-3bad-6530360d6f68Цqueued¤logs�§running¦output†¤bodyÙ.keep_working (generic function with 2 methods)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ×ßÉɰpersist_js_state·has_pluto_hook_features§cell_idÙ$41cefa68-0414-11eb-3bad-6530360d6f68¹depends_on_disabled_cells§runtimeÎ ³eµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$847d0fc2-041d-11eb-2864-79066e223b45Цqueued¤logs�§running¦output†¤bodyÙÆðŸ‘‰ Convert x to an integer using the Integer function. What value does it have? What values do I and R have?
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìà®’°persist_js_state·has_pluto_hook_features§cell_idÙ$847d0fc2-041d-11eb-2864-79066e223b45¹depends_on_disabled_cells§runtimeÎ �õµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$77428072-0403-11eb-0068-81e3728f2ebeЦqueued¤logs�§running¦output†¤bodyÙ—Let's run an experiment with $p=0.25$ and $N=10,000$ .
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌÞܰpersist_js_state·has_pluto_hook_features§cell_idÙ$77428072-0403-11eb-0068-81e3728f2ebe¹depends_on_disabled_cells§runtimeÎ -¢µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9a837b52-0425-11eb-231f-a74405ff6e23Цqueued¤logs�§running¦output†¤bodyÙ/is_susceptible (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÖGó°persist_js_state·has_pluto_hook_features§cell_idÙ$9a837b52-0425-11eb-231f-a74405ff6e23¹depends_on_disabled_cells§runtimeÎ \Vµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$0a967f38-0493-11eb-0624-77e40b24d757Цqueued¤logs�§running¦output†¤bodyÚ ßWe used a let block in this cell to group multiple expressions together, but how is it different from begin or function?
function vs. begin vs. let
Writing functions is a way to group multiple expressions (i.e. lines of code) together into a mini-program. Note the following about functions:
A function always returns one object . This object can be given explicitly by writing return x, or implicitly: Julia functions always return the result of the last expression by default. So f(x) = x+2 is the same as f(x) = return x+2.
Variables defined inside a function are not accessible outside the function . We say that function bodies have a local scope . This helps to keep your program easy to read and write: if you define a local variable, then you don't need to worry about it in the rest of the notebook.
There are two other ways to group epxressions together that you might have seen before: begin and let.
begin
begin will group expressions together, and it takes the value of its last subexpression.
We use it in this notebook when we want multiple expressions to always run together.
let
let also groups multiple expressions together into one, but variables defined inside of it are local : they don't affect code outside of the block. So like begin, it is just a block of code, but like function, it has a local variable scope.
We use it when we want to define some local (temporary) variables to produce a complicated result, without interfering with other cells. Pluto allows only one definition per global variable of the same name, but you can define local variables with the same names whenever you wish!
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìãèɰpersist_js_state·has_pluto_hook_features§cell_idÙ$0a967f38-0493-11eb-0624-77e40b24d757¹depends_on_disabled_cells§runtimeÎ
93µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$28db9d98-04ca-11eb-3606-9fb89fa62f36Цqueued¤logs�§running¦output†¤bodyÙm ¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÖííW°persist_js_state·has_pluto_hook_features§cell_idÙ$28db9d98-04ca-11eb-3606-9fb89fa62f36¹depends_on_disabled_cells§runtimeÎ� ‹µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$8692bf42-0403-11eb-191f-b7d08895274fЦqueued¤logs�§running¦output†¤bodyÚ8Exericse 2.4
👉 Write a function generate_agents(N) that returns a vector of N freshly created Agents. They should all be initially susceptible, except one, chosen at random (i.e. uniformly), who is infectious.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìá{l°persist_js_state·has_pluto_hook_features§cell_idÙ$8692bf42-0403-11eb-191f-b7d08895274f¹depends_on_disabled_cells§runtimeÎ âéµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$da49710e-0420-11eb-092e-4f1173868738Цqueued¤logs�§running¦output†¤bodyÚéExercise 5 - Lecture transcript
(MIT students only) Please see the link for hw 4 transcript document on Canvas . We want each of you to correct about 400 lines, but don’t spend more than 15 minutes on it. See the the beginning of the document for more instructions. :point_right: Please mention the name of the video(s) and the line ranges you edited:
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìåï1°persist_js_state·has_pluto_hook_features§cell_idÙ$da49710e-0420-11eb-092e-4f1173868738¹depends_on_disabled_cells§runtimeÎ ú˵published_object_keys�¸depends_on_skipped_cells§erroredÂÙ$7bb8e426-0495-11eb-3a8b-cbbab61a1631Цqueued¤logs�§running¦output†¤bodyÚ‹:
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Õ÷£ƒ°persist_js_state·has_pluto_hook_features§cell_idÙ$7bb8e426-0495-11eb-3a8b-cbbab61a1631¹depends_on_disabled_cells§runtimeÎ
`tµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$a4c9ccdc-12ca-11eb-072f-e34595520548Цqueued¤logs�§running¦output†¤bodyÚl"(S = [0.99, 0.989, 0.989, 0.988, 0.9875, 0.9875, 0.9875, 0.987, 0.9865, 0.9865, 0.986, 0.9855, 0.985, 0.985, 0.985, 0.985, 0.985, 0.985, 0.985, 0.985, 0.985, 0.985, 0.985, 0.9845, 0.9845, 0.9835, 0.983, 0.982, 0.982, 0.982, 0.982, 0.9815, 0.9815, 0.981, 0.9805, 0.98, 0.98, 0.9795, 0.9795, 0.9795, " ⋯ 21644 bytes ⋯ "0.605, 0.606, 0.606, 0.606, 0.607, 0.6075, 0.6085, 0.609, 0.6095, 0.6095, 0.61, 0.61, 0.61, 0.6105, 0.611, 0.6115, 0.6125, 0.6135, 0.6145, 0.6145, 0.615, 0.615, 0.616, 0.616, 0.617, 0.6185, 0.619, 0.619, 0.619, 0.6205, 0.6205, 0.6205, 0.6205, 0.6215, 0.623, 0.6245, 0.6255, 0.626, 0.6265, 0.6265])"¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ × ¡©°persist_js_state·has_pluto_hook_features§cell_idÙ$a4c9ccdc-12ca-11eb-072f-e34595520548¹depends_on_disabled_cells§runtimeΫ9àµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$21c50840-0435-11eb-1307-7138ecde0691Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÌåÑú°persist_js_state·has_pluto_hook_features§cell_idÙ$21c50840-0435-11eb-1307-7138ecde0691¹depends_on_disabled_cells§runtimeÍê�µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$2ade2694-0425-11eb-2fb2-390da43d9695Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÌâåK°persist_js_state·has_pluto_hook_features§cell_idÙ$2ade2694-0425-11eb-2fb2-390da43d9695¹depends_on_disabled_cells§runtimeÍ7.µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$aa6673d4-0417-11eb-32cc-79560896c195Цqueued¤logs�§running¦output†¤bodyÙ,frequencies (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ò5ž4°persist_js_state·has_pluto_hook_features§cell_idÙ$aa6673d4-0417-11eb-32cc-79560896c195¹depends_on_disabled_cells§runtimeÎ
í;µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$73047bba-0416-11eb-1047-23e9c3dbde05Цqueued¤logs�§running¦output†¤bodyÙ-¤mime©text/html¬rootassignee¾interpretation_of_p_equals_one²last_run_timestampËAÚ Ñü*^°persist_js_state·has_pluto_hook_features§cell_idÙ$73047bba-0416-11eb-1047-23e9c3dbde05¹depends_on_disabled_cells§runtimeÎ ¿ºµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$bf6fd176-04cc-11eb-008a-2fb6ff70a9cbЦqueued¤logs�§running¦output†¤bodyÚExercise 3.2
Alright! Every time that we run the simulation, we get slightly different results, because it is based on randomness. By running the simulation a number of times, you start to get an idea of the mean behaviour of our model. This is the essence of a Monte Carlo method! You use computer-generated randomness to generate samples.
Instead of pressing the button many times, let's have the computer repeat the simulation. In the next cells, we run your simulation num_simulations=20 times with $N=100$ , $p_\text{infection} = 0.02$ , $p_\text{infection} = 0.002$ and $T = 1000$ .
Every single simulation returns a named tuple with the status counts, so the result of multiple simulations will be an array of those. Have a look inside the result, simulations, and make sure that its structure is clear.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìä³°persist_js_state·has_pluto_hook_features§cell_idÙ$bf6fd176-04cc-11eb-008a-2fb6ff70a9cb¹depends_on_disabled_cells§runtimeÎ Ç)µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$43e6e856-0414-11eb-19ca-07358aa8b667Цqueued¤logs�§running¦output†¤bodyÙ/still_missing (generic function with 2 methods)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ×Ô•%°persist_js_state·has_pluto_hook_features§cell_idÙ$43e6e856-0414-11eb-19ca-07358aa8b667¹depends_on_disabled_cells§runtimeΠɵpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$95c598d4-0403-11eb-2328-0175ed564915Цqueued¤logs�§running¦output†¤bodyÙý👉 Write a function sir_mean_plot that returns a plot of the means of $S$ , $I$ and $R$ as a function of time on a single graph.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìä8ɰpersist_js_state·has_pluto_hook_features§cell_idÙ$95c598d4-0403-11eb-2328-0175ed564915¹depends_on_disabled_cells§runtimeÎ Jµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$2b26dc42-0403-11eb-205f-cd2c23d8cb03Цqueued¤logs�§running¦output†¤body´ ¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ØBL°persist_js_state·has_pluto_hook_features§cell_idÙ$2b26dc42-0403-11eb-205f-cd2c23d8cb03¹depends_on_disabled_cells§runtimeÍ"„µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$1ac4b33a-0435-11eb-36f8-8f3f81ae7844Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ìå§P°persist_js_state·has_pluto_hook_features§cell_idÙ$1ac4b33a-0435-11eb-36f8-8f3f81ae7844¹depends_on_disabled_cells§runtimeÍèµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$a8dd5cae-0425-11eb-119c-bfcbf832d695Цqueued¤logs�§running¦output†¤bodyÙ,is_infected (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÖR"}°persist_js_state·has_pluto_hook_features§cell_idÙ$a8dd5cae-0425-11eb-119c-bfcbf832d695¹depends_on_disabled_cells§runtimeÎ »µpublished_object_keys�¸depends_on_skipped_cells§errored±cell_dependenciesÞ ŽÙ$f1f89502-0494-11eb-2303-0b79d8bbd13f„´precedence_heuristic §cell_idÙ$f1f89502-0494-11eb-2303-0b79d8bbd13f´downstream_cells_map�ºfrequencies_plot_with_mean‘Ù$06089d1e-0495-11eb-0ace-a7a7dc60e5b2²upstream_cells_map�§missing�Ù$95771ce2-0403-11eb-3056-f1dc3a8b7ec3„´precedence_heuristic §cell_idÙ$95771ce2-0403-11eb-3056-f1dc3a8b7ec3´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$e6219c7c-0420-11eb-3faa-13126f7c8007„´precedence_heuristic §cell_idÙ$e6219c7c-0420-11eb-3faa-13126f7c8007´downstream_cells_map�®lines_i_edited�²upstream_cells_map‚§@md_str�¨getindex�Ù$b817f466-04d4-11eb-0a26-c1c667f9f7f7„´precedence_heuristic §cell_idÙ$b817f466-04d4-11eb-0a26-c1c667f9f7f7´downstream_cells_map€²upstream_cells_mapާ@md_str�Base.getindex�§Missing�¡!�ª@isdefined�¤Bool�still_missing‘Ù$43e6e856-0414-11eb-19ca-07358aa8b667£isa�¤Base�§correct‘Ù$3d88c056-0414-11eb-0025-05d3aff1588b¬keep_working‘Ù$41cefa68-0414-11eb-3bad-6530360d6f68«not_defined‘Ù$3c0528a0-0414-11eb-2f68-a5657ab9e73d¢==�©bernoulli‘Ù$d8797684-0414-11eb-1869-5b1e2c469011Ù$08e2bc64-0417-11eb-1457-21c0d18e8c51„´precedence_heuristic §cell_idÙ$08e2bc64-0417-11eb-1457-21c0d18e8c51´downstream_cells_map€²upstream_cells_mapƒ§@md_str�¤hint‘Ù$48a16c42-0414-11eb-0e0c-bf52bbb0f618¨getindex�Ù$bb8aeb58-042f-11eb-18b8-f995631df619„´precedence_heuristic §cell_idÙ$bb8aeb58-042f-11eb-18b8-f995631df619´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$223933a4-042c-11eb-10d3-852229f25a35„´precedence_heuristic §cell_idÙ$223933a4-042c-11eb-10d3-852229f25a35´downstream_cells_map�±AbstractInfection”Ù$1a654bdc-0421-11eb-2c38-7d35060e2565Ù$8a1d5aea-04ae-11eb-2177-eb37822db4f1Ù$32cea7ba-0429-11eb-06bc-a5f4ae3ffe37Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9²upstream_cells_map€Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2„´precedence_heuristic §cell_idÙ$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2´downstream_cells_map�¥AgentŸÙ$82f2580a-04c8-11eb-1eea-bdb4e50eee3bÙ$98beb336-0425-11eb-3886-4f8cfd210288Ù$7c515a7a-04d5-11eb-0f36-4fcebff709d5Ù$9a837b52-0425-11eb-231f-a74405ff6e23Ù$a8dd5cae-0425-11eb-119c-bfcbf832d695Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21fÙ$6d480cf0-0425-11eb-18a9-1737455371d7Ù$393041ec-049f-11eb-3089-2faf378445f3Ù$221bc0ac-04aa-11eb-1331-2b16ebc1ee57Ù$9c39974c-04a5-11eb-184d-317eb542452cÙ$759bc42e-04ab-11eb-0ab1-b12e008c02a9Ù$1491a078-04aa-11eb-0106-19a3cf1e94b0Ù$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272Ù$8a1d5aea-04ae-11eb-2177-eb37822db4f1Ù$32cea7ba-0429-11eb-06bc-a5f4ae3ffe37²upstream_cells_map‚¥Int64�¯InfectionStatus‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7Ù$7f635722-04d0-11eb-3209-4b603c9e843c„´precedence_heuristic §cell_idÙ$7f635722-04d0-11eb-3209-4b603c9e843c´downstream_cells_map€²upstream_cells_map‚«simulations‘Ù$80c2cd88-04b1-11eb-326e-0120a39405easir_mean_plot‘Ù$10cf6db8-04b8-11eb-2267-3db6d7f9c89aÙ$7c515a7a-04d5-11eb-0f36-4fcebff709d5„´precedence_heuristic §cell_idÙ$7c515a7a-04d5-11eb-0f36-4fcebff709d5´downstream_cells_map€²upstream_cells_mapŠ¡I‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7§correct‘Ù$3d88c056-0414-11eb-0025-05d3aff1588b¬keep_working‘Ù$41cefa68-0414-11eb-3bad-6530360d6f68¡!�«not_defined‘Ù$3c0528a0-0414-11eb-2f68-a5657ab9e73dª@isdefined�¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2¡R‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¢==�«set_status!‘Ù$98beb336-0425-11eb-3886-4f8cfd210288Ù$107e65a4-0403-11eb-0c14-37d8d828b469„´precedence_heuristic §cell_idÙ$107e65a4-0403-11eb-0c14-37d8d828b469´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$1c6aa208-04d1-11eb-0b87-cf429e6ff6d0„´precedence_heuristic §cell_idÙ$1c6aa208-04d1-11eb-0b87-cf429e6ff6d0´downstream_cells_map€²upstream_cells_map€Ù$80e6f1e0-04b1-11eb-0d4e-475f1d80c2bb„´precedence_heuristic §cell_idÙ$80e6f1e0-04b1-11eb-0d4e-475f1d80c2bb´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$7f4e121c-041d-11eb-0dff-cd0cbfdfd606„´precedence_heuristic §cell_idÙ$7f4e121c-041d-11eb-0dff-cd0cbfdfd606´downstream_cells_map�«test_status�²upstream_cells_map�§missing�Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9„´precedence_heuristic §cell_idÙ$3d3b672c-0426-11eb-0a36-153ce3c276b9´downstream_cells_map�ªsimulation”Ù$b92f1cec-04ae-11eb-0072-3535d1118494Ù$2c62b4ae-04b3-11eb-0080-a1035a7e31a2Ù$c5156c72-04af-11eb-1106-b13969b036caÙ$38b1aa5a-04cf-11eb-11a2-930741fc9076²upstream_cells_map‹¡:�£sum�±AbstractInfection‘Ù$223933a4-042c-11eb-10d3-852229f25a35¦sweep!‘Ù$32cea7ba-0429-11eb-06bc-a5f4ae3ffe37§Integer�¯generate_agents‘Ù$6d480cf0-0425-11eb-18a9-1737455371d7¡I‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¡S‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¥push!�¡R‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¢==�Ù$4f19e872-0414-11eb-0dfd-e53d2aecc4dc„´precedence_heuristic §cell_idÙ$4f19e872-0414-11eb-0dfd-e53d2aecc4dc´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$759bc42e-04ab-11eb-0ab1-b12e008c02a9„´precedence_heuristic §cell_idÙ$759bc42e-04ab-11eb-0ab1-b12e008c02a9´downstream_cells_map€²upstream_cells_mapÞ §@md_str�Base.getindex�¡!�ª@isdefined�¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2©interact!‘Ù$221bc0ac-04aa-11eb-1331-2b16ebc1ee57¤Base�¡I‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¡S‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7§correct‘Ù$3d88c056-0414-11eb-0025-05d3aff1588b¬keep_working‘Ù$41cefa68-0414-11eb-3bad-6530360d6f68«not_defined‘Ù$3c0528a0-0414-11eb-2f68-a5657ab9e73d¢!=�¡R‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¢==�¦almost‘Ù$461586dc-0414-11eb-00f3-4984b57bfac5±InfectionRecovery‘Ù$1a654bdc-0421-11eb-2c38-7d35060e2565Ù$5689841e-0414-11eb-0492-63c77ddbd136„´precedence_heuristic §cell_idÙ$5689841e-0414-11eb-0492-63c77ddbd136´downstream_cells_map€²upstream_cells_map�¨bigbreak‘Ù$39dffa3c-0414-11eb-0197-e72b299e9c63Ù$99ef7b2a-0403-11eb-08ef-e1023cd151ae„´precedence_heuristic §cell_idÙ$99ef7b2a-0403-11eb-08ef-e1023cd151ae´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$77b54c10-0403-11eb-16ad-65374d29a817„´precedence_heuristic §cell_idÙ$77b54c10-0403-11eb-16ad-65374d29a817´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$7768a2dc-0403-11eb-39b7-fd660dc952fe„´precedence_heuristic §cell_idÙ$7768a2dc-0403-11eb-39b7-fd660dc952fe´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$60a8b708-04c8-11eb-37b1-3daec644ac90„´precedence_heuristic §cell_idÙ$60a8b708-04c8-11eb-37b1-3daec644ac90´downstream_cells_map€²upstream_cells_map€Ù$95eb9f88-0403-11eb-155b-7b2d3a07cff0„´precedence_heuristic §cell_idÙ$95eb9f88-0403-11eb-155b-7b2d3a07cff0´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$955321de-0403-11eb-04ce-fb1670dfbb9e„´precedence_heuristic §cell_idÙ$955321de-0403-11eb-04ce-fb1670dfbb9e´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$ae70625a-041f-11eb-3082-0753419d6d57„´precedence_heuristic §cell_idÙ$ae70625a-041f-11eb-3082-0753419d6d57´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$843fd63c-04d0-11eb-0113-c58d346179d6„´precedence_heuristic §cell_idÙ$843fd63c-04d0-11eb-0113-c58d346179d6´downstream_cells_map€²upstream_cells_map€Ù$189cae1e-0424-11eb-2666-65bf297d8bdd„´precedence_heuristic §cell_idÙ$189cae1e-0424-11eb-2666-65bf297d8bdd´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$7f744644-041d-11eb-08a0-3719cc0adeb7„´precedence_heuristic §cell_idÙ$7f744644-041d-11eb-08a0-3719cc0adeb7´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$488771e2-049f-11eb-3b0a-0de260457731„´precedence_heuristic §cell_idÙ$488771e2-049f-11eb-3b0a-0de260457731´downstream_cells_map€²upstream_cells_map�¯generate_agents‘Ù$6d480cf0-0425-11eb-18a9-1737455371d7Ù$393041ec-049f-11eb-3089-2faf378445f3„´precedence_heuristic §cell_idÙ$393041ec-049f-11eb-3089-2faf378445f3´downstream_cells_map€²upstream_cells_mapÞ §@md_str�£sum�§Missing�¡!�¦Vector�¦length�§correct‘Ù$3d88c056-0414-11eb-0025-05d3aff1588b¬keep_working‘Ù$41cefa68-0414-11eb-3bad-6530360d6f68«not_defined‘Ù$3c0528a0-0414-11eb-2f68-a5657ab9e73d¢!=�¢==�¦almost‘Ù$461586dc-0414-11eb-00f3-4984b57bfac5£Set�Base.getindex�§Nothing�ª@isdefined�¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2still_missing‘Ù$43e6e856-0414-11eb-19ca-07358aa8b667¯generate_agents‘Ù$6d480cf0-0425-11eb-18a9-1737455371d7£isa�¤Base�£all�¡I‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7Ù$531d13c2-0414-11eb-0acd-4905a684869d„´precedence_heuristic §cell_idÙ$531d13c2-0414-11eb-0acd-4905a684869d´downstream_cells_map€²upstream_cells_map„§@md_str�§student‘Ù$095cbf46-0403-11eb-0c37-35de9562cebc¢==�¨getindex�Ù$221bc0ac-04aa-11eb-1331-2b16ebc1ee57„´precedence_heuristic §cell_idÙ$221bc0ac-04aa-11eb-1331-2b16ebc1ee57´downstream_cells_map�©interact!•Ù$9c39974c-04a5-11eb-184d-317eb542452cÙ$759bc42e-04ab-11eb-0ab1-b12e008c02a9Ù$1491a078-04aa-11eb-0106-19a3cf1e94b0Ù$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272Ù$8a1d5aea-04ae-11eb-2177-eb37822db4f1²upstream_cells_map‰±InfectionRecovery‘Ù$1a654bdc-0421-11eb-2c38-7d35060e2565¡I‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¡S‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7«Reinfection�¡+�¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2¡R‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¢==�©bernoulli‘Ù$d8797684-0414-11eb-1869-5b1e2c469011Ù$32cea7ba-0429-11eb-06bc-a5f4ae3ffe37„´precedence_heuristic §cell_idÙ$32cea7ba-0429-11eb-06bc-a5f4ae3ffe37´downstream_cells_map�¦sweep!‘Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9²upstream_cells_map„¥step!‘Ù$8a1d5aea-04ae-11eb-2177-eb37822db4f1±AbstractInfection‘Ù$223933a4-042c-11eb-10d3-852229f25a35¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2¦Vector�Ù$06f30b2a-0403-11eb-0f05-8badebe1011d„´precedence_heuristic §cell_idÙ$06f30b2a-0403-11eb-0f05-8badebe1011d´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$9c39974c-04a5-11eb-184d-317eb542452c„´precedence_heuristic §cell_idÙ$9c39974c-04a5-11eb-184d-317eb542452c´downstream_cells_map€²upstream_cells_map…±InfectionRecovery‘Ù$1a654bdc-0421-11eb-2c38-7d35060e2565¡I‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¡S‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2©interact!‘Ù$221bc0ac-04aa-11eb-1331-2b16ebc1ee57Ù$1ddbaa18-0494-11eb-1fc8-250ab6ae89f1„´precedence_heuristic §cell_idÙ$1ddbaa18-0494-11eb-1fc8-250ab6ae89f1´downstream_cells_map€²upstream_cells_map‚°large_experiment‘Ù$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8½frequencies_plot_with_maximum‘Ù$823364ce-041c-11eb-2467-7ffa4f751527Ù$06089d1e-0495-11eb-0ace-a7a7dc60e5b2„´precedence_heuristic §cell_idÙ$06089d1e-0495-11eb-0ace-a7a7dc60e5b2´downstream_cells_map€²upstream_cells_map‚°large_experiment‘Ù$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8ºfrequencies_plot_with_mean‘Ù$f1f89502-0494-11eb-2303-0b79d8bbd13fÙ$15187690-0403-11eb-2dfd-fd924faa3513„´precedence_heuristic§cell_idÙ$15187690-0403-11eb-2dfd-fd924faa3513´downstream_cells_map‚§PlutoUI�¥Plots�²upstream_cells_mapƒ§Pkg.add�£Pkg‘Ù$12cc2940-0403-11eb-19a7-bb570de58f6f¦plotly�Ù$d8abd2f6-0416-11eb-1c2a-f9157d9760a7„´precedence_heuristic §cell_idÙ$d8abd2f6-0416-11eb-1c2a-f9157d9760a7´downstream_cells_map�°small_experiment‘Ù$1ca7a8c2-041a-11eb-146a-15b8cdeaea72²upstream_cells_map�do_experiment‘Ù$cdaade9c-0416-11eb-0550-7b5b3d33e240Ù$9374e63c-0493-11eb-0952-4b97512d7cdb„´precedence_heuristic §cell_idÙ$9374e63c-0493-11eb-0952-4b97512d7cdb´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$2d3bba2a-04a8-11eb-2c40-87794b6aeeac„´precedence_heuristic §cell_idÙ$2d3bba2a-04a8-11eb-2c40-87794b6aeeac´downstream_cells_map€²upstream_cells_map…§@md_str�Base.getindex�¤Base�®Base.Docs.HTML�©@html_str�Ù$10cf6db8-04b8-11eb-2267-3db6d7f9c89a„´precedence_heuristic §cell_idÙ$10cf6db8-04b8-11eb-2267-3db6d7f9c89a´downstream_cells_map�sir_mean_plot‘Ù$7f635722-04d0-11eb-3209-4b603c9e843c²upstream_cells_mapŠªNamedTuple�¦length�¡:�£sum�£map�¤plot�¡/�¥first�¥plot!�¦Vector�Ù$dfb99ace-04cf-11eb-0739-7d694c837d59„´precedence_heuristic §cell_idÙ$dfb99ace-04cf-11eb-0739-7d694c837d59´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$271ec5f0-041d-11eb-041b-db46ec1465e0„´precedence_heuristic §cell_idÙ$271ec5f0-041d-11eb-041b-db46ec1465e0´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$7946d83a-04a0-11eb-224b-2b315e87bc84„´precedence_heuristic §cell_idÙ$7946d83a-04a0-11eb-224b-2b315e87bc84´downstream_cells_map€²upstream_cells_map€Ù$02b0c2fc-0415-11eb-2b40-7bca8ea4eef9„´precedence_heuristic §cell_idÙ$02b0c2fc-0415-11eb-2b40-7bca8ea4eef9´downstream_cells_map€²upstream_cells_map€Ù$9635c944-0403-11eb-3982-4df509f6a556„´precedence_heuristic §cell_idÙ$9635c944-0403-11eb-3982-4df509f6a556´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$f3f81172-041c-11eb-2b9b-e99b7b9400ed„´precedence_heuristic §cell_idÙ$f3f81172-041c-11eb-2b9b-e99b7b9400ed´downstream_cells_map€²upstream_cells_map…§@md_str�Base.getindex�¤Base�®Base.Docs.HTML�©@html_str�Ù$8a1d5aea-04ae-11eb-2177-eb37822db4f1„´precedence_heuristic §cell_idÙ$8a1d5aea-04ae-11eb-2177-eb37822db4f1´downstream_cells_map�¥step!‘Ù$32cea7ba-0429-11eb-06bc-a5f4ae3ffe37²upstream_cells_map…¦Vector�±AbstractInfection‘Ù$223933a4-042c-11eb-10d3-852229f25a35¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2¤rand�©interact!‘Ù$221bc0ac-04aa-11eb-1331-2b16ebc1ee57Ù$4ad11052-042c-11eb-3643-8b2b3e1269bc„´precedence_heuristic §cell_idÙ$4ad11052-042c-11eb-3643-8b2b3e1269bc´downstream_cells_map€²upstream_cells_map€Ù$76d117d4-0403-11eb-05d2-c5ea47d06f43„´precedence_heuristic §cell_idÙ$76d117d4-0403-11eb-05d2-c5ea47d06f43´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$095cbf46-0403-11eb-0c37-35de9562cebc„´precedence_heuristic §cell_idÙ$095cbf46-0403-11eb-0c37-35de9562cebc´downstream_cells_map�§student’Ù$03a85970-0403-11eb-334a-812b59c0905bÙ$531d13c2-0414-11eb-0acd-4905a684869d²upstream_cells_map€Ù$6d5c6a84-0415-11eb-3fdf-9355200cb520„´precedence_heuristic §cell_idÙ$6d5c6a84-0415-11eb-3fdf-9355200cb520´downstream_cells_map�recovery_time’Ù$c61f35ea-04d6-11eb-2503-17a79f8d0298Ù$cdaade9c-0416-11eb-0550-7b5b3d33e240²upstream_cells_map†¢<=�¥throw�¡+�£â‰¤�ArgumentError�©bernoulli‘Ù$d8797684-0414-11eb-1869-5b1e2c469011Ù$26e2978e-0435-11eb-0d61-25f552d2771e„´precedence_heuristic §cell_idÙ$26e2978e-0435-11eb-0d61-25f552d2771e´downstream_cells_map€²upstream_cells_map€Ù$6de37d6c-0415-11eb-1b05-85ac820016c7„´precedence_heuristic §cell_idÙ$6de37d6c-0415-11eb-1b05-85ac820016c7´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$18d308c4-0424-11eb-176d-49feec6889cf„´precedence_heuristic §cell_idÙ$18d308c4-0424-11eb-176d-49feec6889cf´downstream_cells_map�ªtest_agent�²upstream_cells_map�§missing�Ù$46133a74-04b1-11eb-0b46-0bc74e564680„´precedence_heuristic §cell_idÙ$46133a74-04b1-11eb-0b46-0bc74e564680´downstream_cells_map€²upstream_cells_map€Ù$771c8f0c-0403-11eb-097e-ab24d0714ad5„´precedence_heuristic §cell_idÙ$771c8f0c-0403-11eb-097e-ab24d0714ad5´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$3f497394-0a46-11eb-3369-8189905f011c„´precedence_heuristic §cell_idÙ$3f497394-0a46-11eb-3369-8189905f011c´downstream_cells_map€²upstream_cells_map€Ù$80c2cd88-04b1-11eb-326e-0120a39405ea„´precedence_heuristic §cell_idÙ$80c2cd88-04b1-11eb-326e-0120a39405ea´downstream_cells_map�«simulations“Ù$9cd2bb00-04b1-11eb-1d83-a703907141a7Ù$7f635722-04d0-11eb-3209-4b603c9e843cÙ$a4c9ccdc-12ca-11eb-072f-e34595520548²upstream_cells_map‚²repeat_simulations‘Ù$38b1aa5a-04cf-11eb-11a2-930741fc9076±InfectionRecovery‘Ù$1a654bdc-0421-11eb-2c38-7d35060e2565Ù$105d347e-041c-11eb-2fc8-1d9e5eda2be0„´precedence_heuristic §cell_idÙ$105d347e-041c-11eb-2fc8-1d9e5eda2be0´downstream_cells_map€²upstream_cells_map€Ù$2c62b4ae-04b3-11eb-0080-a1035a7e31a2„´precedence_heuristic §cell_idÙ$2c62b4ae-04b3-11eb-0080-a1035a7e31a2´downstream_cells_map€²upstream_cells_map‚ªsimulation‘Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9±InfectionRecovery‘Ù$1a654bdc-0421-11eb-2c38-7d35060e2565Ù$6db6c894-0415-11eb-305a-c75b119d89e9„´precedence_heuristic §cell_idÙ$6db6c894-0415-11eb-305a-c75b119d89e9´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$77db111e-0403-11eb-2dea-4b42ceed65d6„´precedence_heuristic §cell_idÙ$77db111e-0403-11eb-2dea-4b42ceed65d6´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$6d480cf0-0425-11eb-18a9-1737455371d7„´precedence_heuristic §cell_idÙ$6d480cf0-0425-11eb-18a9-1737455371d7´downstream_cells_map�¯generate_agents“Ù$488771e2-049f-11eb-3b0a-0de260457731Ù$393041ec-049f-11eb-3089-2faf378445f3Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9²upstream_cells_map†¡I‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¡S‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¡:�¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2¤rand�§Integer�Ù$287ee7aa-0435-11eb-0ca3-951dbbe69404„´precedence_heuristic §cell_idÙ$287ee7aa-0435-11eb-0ca3-951dbbe69404´downstream_cells_map�³sir_mean_error_plot�²upstream_cells_map…ªNamedTuple�¦length�§missing�¥first�¦Vector�Ù$3d88c056-0414-11eb-0025-05d3aff1588b„´precedence_heuristic §cell_idÙ$3d88c056-0414-11eb-0025-05d3aff1588b´downstream_cells_map�§correct˜Ù$b817f466-04d4-11eb-0a26-c1c667f9f7f7Ù$c61f35ea-04d6-11eb-2503-17a79f8d0298Ù$7c515a7a-04d5-11eb-0f36-4fcebff709d5Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21fÙ$393041ec-049f-11eb-3089-2faf378445f3Ù$759bc42e-04ab-11eb-0ab1-b12e008c02a9Ù$1491a078-04aa-11eb-0106-19a3cf1e94b0Ù$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272²upstream_cells_map…³Markdown.Admonition�¤yays‘Ù$3f5e0af8-0414-11eb-34a7-a71e7aaf6443«Markdown.MD�¨Markdown�¤rand�Ù$03a85970-0403-11eb-334a-812b59c0905b„´precedence_heuristic §cell_idÙ$03a85970-0403-11eb-334a-812b59c0905b´downstream_cells_map€²upstream_cells_mapƒ§@md_str�§student‘Ù$095cbf46-0403-11eb-0c37-35de9562cebc¨getindex�Ù$6d906d0c-0415-11eb-0c1c-b5c0aca841db„´precedence_heuristic §cell_idÙ$6d906d0c-0415-11eb-0c1c-b5c0aca841db´downstream_cells_map€²upstream_cells_mapƒ§@md_str�¤hint‘Ù$48a16c42-0414-11eb-0e0c-bf52bbb0f618¨getindex�Ù$866299e8-0403-11eb-085d-2b93459cc141„´precedence_heuristic §cell_idÙ$866299e8-0403-11eb-085d-2b93459cc141´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$461586dc-0414-11eb-00f3-4984b57bfac5„´precedence_heuristic §cell_idÙ$461586dc-0414-11eb-00f3-4984b57bfac5´downstream_cells_map�¦almost’Ù$393041ec-049f-11eb-3089-2faf378445f3Ù$759bc42e-04ab-11eb-0ab1-b12e008c02a9²upstream_cells_mapƒ³Markdown.Admonition�«Markdown.MD�¨Markdown�Ù$c5156c72-04af-11eb-1106-b13969b036ca„´precedence_heuristic §cell_idÙ$c5156c72-04af-11eb-1106-b13969b036ca´downstream_cells_map€²upstream_cells_map†¡:�¤plot�run_basic_sir‘Ù$28db9d98-04ca-11eb-3606-9fb89fa62f36ªsimulation‘Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9¥plot!�±InfectionRecovery‘Ù$1a654bdc-0421-11eb-2c38-7d35060e2565Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21f„´precedence_heuristic §cell_idÙ$c4a8694a-04d4-11eb-1eef-c9e037e6b21f´downstream_cells_map€²upstream_cells_mapÞ §@md_str�Base.getindex�§Missing�¡!�®is_susceptible‘Ù$9a837b52-0425-11eb-231f-a74405ff6e23ª@isdefined�¤Bool�¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2still_missing‘Ù$43e6e856-0414-11eb-19ca-07358aa8b667«is_infected‘Ù$a8dd5cae-0425-11eb-119c-bfcbf832d695£isa�¡I‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¡S‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7£===�¬keep_working‘Ù$41cefa68-0414-11eb-3bad-6530360d6f68¤Base�«not_defined‘Ù$3c0528a0-0414-11eb-2f68-a5657ab9e73d§correct‘Ù$3d88c056-0414-11eb-0025-05d3aff1588b¡R‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7Ù$1491a078-04aa-11eb-0106-19a3cf1e94b0„´precedence_heuristic §cell_idÙ$1491a078-04aa-11eb-0106-19a3cf1e94b0´downstream_cells_map€²upstream_cells_mapÞ §@md_str�Base.getindex�¡!�ª@isdefined�¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2©interact!‘Ù$221bc0ac-04aa-11eb-1331-2b16ebc1ee57¤Base�¡I‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¡S‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7§correct‘Ù$3d88c056-0414-11eb-0025-05d3aff1588b¬keep_working‘Ù$41cefa68-0414-11eb-3bad-6530360d6f68«not_defined‘Ù$3c0528a0-0414-11eb-2f68-a5657ab9e73d¢!=�¡R‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¢==�±InfectionRecovery‘Ù$1a654bdc-0421-11eb-2c38-7d35060e2565Ù$c5c7cb86-041b-11eb-3360-45463105f3c9„´precedence_heuristic §cell_idÙ$c5c7cb86-041b-11eb-3360-45463105f3c9´downstream_cells_map€²upstream_cells_map€Ù$01341648-0403-11eb-2212-db450c299f35„´precedence_heuristic §cell_idÙ$01341648-0403-11eb-2212-db450c299f35´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$d8797684-0414-11eb-1869-5b1e2c469011„´precedence_heuristic §cell_idÙ$d8797684-0414-11eb-1869-5b1e2c469011´downstream_cells_map�©bernoulli“Ù$b817f466-04d4-11eb-0a26-c1c667f9f7f7Ù$6d5c6a84-0415-11eb-3fdf-9355200cb520Ù$221bc0ac-04aa-11eb-1331-2b16ebc1ee57²upstream_cells_map„¡<�¦isless�¦Number�¤rand�Ù$48a16c42-0414-11eb-0e0c-bf52bbb0f618„´precedence_heuristic §cell_idÙ$48a16c42-0414-11eb-0e0c-bf52bbb0f618´downstream_cells_map�¤hint“Ù$6d906d0c-0415-11eb-0c1c-b5c0aca841dbÙ$08e2bc64-0417-11eb-1457-21c0d18e8c51Ù$9cf9080a-04b1-11eb-12a0-17013f2d37f5²upstream_cells_mapƒ³Markdown.Admonition�«Markdown.MD�¨Markdown�Ù$98beb336-0425-11eb-3886-4f8cfd210288„´precedence_heuristic §cell_idÙ$98beb336-0425-11eb-3886-4f8cfd210288´downstream_cells_map�«set_status!‘Ù$7c515a7a-04d5-11eb-0f36-4fcebff709d5²upstream_cells_map‚¯InfectionStatus‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2Ù$bb63f3cc-042f-11eb-04ff-a128aec3c378„´precedence_heuristic §cell_idÙ$bb63f3cc-042f-11eb-04ff-a128aec3c378´downstream_cells_map€²upstream_cells_map€Ù$61c00724-0403-11eb-228d-17c11670e5d1„´precedence_heuristic §cell_idÙ$61c00724-0403-11eb-228d-17c11670e5d1´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$9cf9080a-04b1-11eb-12a0-17013f2d37f5„´precedence_heuristic §cell_idÙ$9cf9080a-04b1-11eb-12a0-17013f2d37f5´downstream_cells_map€²upstream_cells_mapƒ§@md_str�¤hint‘Ù$48a16c42-0414-11eb-0e0c-bf52bbb0f618¨getindex�Ù$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8„´precedence_heuristic §cell_idÙ$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8´downstream_cells_map�°large_experiment”Ù$8a28c56e-04b4-11eb-279c-3b4dfb2a9f9bÙ$1ddbaa18-0494-11eb-1fc8-250ab6ae89f1Ù$06089d1e-0495-11eb-0ace-a7a7dc60e5b2Ù$7bb8e426-0495-11eb-3a8b-cbbab61a1631²upstream_cells_map�do_experiment‘Ù$cdaade9c-0416-11eb-0550-7b5b3d33e240Ù$61789646-0403-11eb-0042-f3b8308f11ba„´precedence_heuristic §cell_idÙ$61789646-0403-11eb-0042-f3b8308f11ba´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$39dffa3c-0414-11eb-0197-e72b299e9c63„´precedence_heuristic §cell_idÙ$39dffa3c-0414-11eb-0197-e72b299e9c63´downstream_cells_map�¨bigbreak’Ù$2b26dc42-0403-11eb-205f-cd2c23d8cb03Ù$5689841e-0414-11eb-0492-63c77ddbd136²upstream_cells_mapƒ¤Base�®Base.Docs.HTML�©@html_str�Ù$5950b37e-0a46-11eb-3480-d5520013692e„´precedence_heuristic §cell_idÙ$5950b37e-0a46-11eb-3480-d5520013692e´downstream_cells_map€²upstream_cells_map€Ù$cdaade9c-0416-11eb-0550-7b5b3d33e240„´precedence_heuristic §cell_idÙ$cdaade9c-0416-11eb-0550-7b5b3d33e240´downstream_cells_map�do_experiment’Ù$d8abd2f6-0416-11eb-1c2a-f9157d9760a7Ù$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8²upstream_cells_mapƒ¡:�recovery_time‘Ù$6d5c6a84-0415-11eb-3fdf-9355200cb520£map�Ù$88c53208-041d-11eb-3b1e-31b57ba99f05„´precedence_heuristic §cell_idÙ$88c53208-041d-11eb-3b1e-31b57ba99f05´downstream_cells_map€²upstream_cells_map€Ù$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272„´precedence_heuristic §cell_idÙ$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272´downstream_cells_map€²upstream_cells_map�§@md_str�Base.getindex�¡!�ª@isdefined�¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2©interact!‘Ù$221bc0ac-04aa-11eb-1331-2b16ebc1ee57¤Base�¡I‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7§correct‘Ù$3d88c056-0414-11eb-0025-05d3aff1588b¬keep_working‘Ù$41cefa68-0414-11eb-3bad-6530360d6f68«not_defined‘Ù$3c0528a0-0414-11eb-2f68-a5657ab9e73d¢!=�¡R‘Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7¢==�±InfectionRecovery‘Ù$1a654bdc-0421-11eb-2c38-7d35060e2565Ù$887d27fc-04bc-11eb-0ab9-eb95ef9607f8„´precedence_heuristic §cell_idÙ$887d27fc-04bc-11eb-0ab9-eb95ef9607f8´downstream_cells_map€²upstream_cells_map€Ù$d57c6a5a-041b-11eb-3ab4-774a2d45a891„´precedence_heuristic §cell_idÙ$d57c6a5a-041b-11eb-3ab4-774a2d45a891´downstream_cells_map€²upstream_cells_map€Ù$12cc2940-0403-11eb-19a7-bb570de58f6f„´precedence_heuristic§cell_idÙ$12cc2940-0403-11eb-19a7-bb570de58f6f´downstream_cells_map�£Pkg’Ù$12cc2940-0403-11eb-19a7-bb570de58f6fÙ$15187690-0403-11eb-2dfd-fd924faa3513²upstream_cells_mapƒ£Pkg‘Ù$12cc2940-0403-11eb-19a7-bb570de58f6f¬Pkg.activate�©mktempdir�Ù$76f62d64-0403-11eb-27e2-3de58366b619„´precedence_heuristic §cell_idÙ$76f62d64-0403-11eb-27e2-3de58366b619´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$860790fc-0403-11eb-2f2e-355f77dcc7af„´precedence_heuristic §cell_idÙ$860790fc-0403-11eb-2f2e-355f77dcc7af´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$b21475c6-04ac-11eb-1366-f3b5e967402d„´precedence_heuristic §cell_idÙ$b21475c6-04ac-11eb-1366-f3b5e967402d´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$823364ce-041c-11eb-2467-7ffa4f751527„´precedence_heuristic §cell_idÙ$823364ce-041c-11eb-2467-7ffa4f751527´downstream_cells_map�½frequencies_plot_with_maximum‘Ù$1ddbaa18-0494-11eb-1fc8-250ab6ae89f1²upstream_cells_map…£bar�¦vline!�«frequencies‘Ù$aa6673d4-0417-11eb-32cc-79560896c195§maximum�¦Vector�Ù$619c8a10-0403-11eb-2e89-8b0974fb01d0„´precedence_heuristic §cell_idÙ$619c8a10-0403-11eb-2e89-8b0974fb01d0´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$38b1aa5a-04cf-11eb-11a2-930741fc9076„´precedence_heuristic §cell_idÙ$38b1aa5a-04cf-11eb-11a2-930741fc9076´downstream_cells_map�²repeat_simulations‘Ù$80c2cd88-04b1-11eb-326e-0120a39405ea²upstream_cells_mapƒ¡:�£map�ªsimulation‘Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9Ù$8dd97820-04a5-11eb-36c0-8f92d4b859a8„´precedence_heuristic §cell_idÙ$8dd97820-04a5-11eb-36c0-8f92d4b859a8´downstream_cells_map€²upstream_cells_map€Ù$df8547b4-0400-11eb-07c6-fb370b61c2b6„´precedence_heuristic §cell_idÙ$df8547b4-0400-11eb-07c6-fb370b61c2b6´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$1d3356c4-0403-11eb-0f48-01b5eb14a585„´precedence_heuristic §cell_idÙ$1d3356c4-0403-11eb-0f48-01b5eb14a585´downstream_cells_map€²upstream_cells_mapƒ¤Base�®Base.Docs.HTML�©@html_str�Ù$82f2580a-04c8-11eb-1eea-bdb4e50eee3b„´precedence_heuristic §cell_idÙ$82f2580a-04c8-11eb-1eea-bdb4e50eee3b´downstream_cells_map€²upstream_cells_map�¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2Ù$86d98d0a-0403-11eb-215b-c58ad721a90b„´precedence_heuristic §cell_idÙ$86d98d0a-0403-11eb-215b-c58ad721a90b´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$dc784864-0430-11eb-1478-d1153e017310„´precedence_heuristic §cell_idÙ$dc784864-0430-11eb-1478-d1153e017310´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$3f5e0af8-0414-11eb-34a7-a71e7aaf6443„´precedence_heuristic §cell_idÙ$3f5e0af8-0414-11eb-34a7-a71e7aaf6443´downstream_cells_map�¤yays‘Ù$3d88c056-0414-11eb-0025-05d3aff1588b²upstream_cells_map‚§@md_str�¨getindex�Ù$3c0528a0-0414-11eb-2f68-a5657ab9e73d„´precedence_heuristic §cell_idÙ$3c0528a0-0414-11eb-2f68-a5657ab9e73d´downstream_cells_map�«not_defined˜Ù$b817f466-04d4-11eb-0a26-c1c667f9f7f7Ù$c61f35ea-04d6-11eb-2503-17a79f8d0298Ù$7c515a7a-04d5-11eb-0f36-4fcebff709d5Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21fÙ$393041ec-049f-11eb-3089-2faf378445f3Ù$759bc42e-04ab-11eb-0ab1-b12e008c02a9Ù$1491a078-04aa-11eb-0106-19a3cf1e94b0Ù$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272²upstream_cells_map‡§@md_str�¦string�³Markdown.Admonition�«Markdown.MD�Markdown.Code�¨Markdown�¨getindex�Ù$7335de44-042f-11eb-2873-8bceef722432„´precedence_heuristic §cell_idÙ$7335de44-042f-11eb-2873-8bceef722432´downstream_cells_map€²upstream_cells_map€Ù$406aabea-04a5-11eb-06b8-312879457c42„´precedence_heuristic §cell_idÙ$406aabea-04a5-11eb-06b8-312879457c42´downstream_cells_map€²upstream_cells_map€Ù$c61f35ea-04d6-11eb-2503-17a79f8d0298„´precedence_heuristic §cell_idÙ$c61f35ea-04d6-11eb-2503-17a79f8d0298´downstream_cells_map€²upstream_cells_mapÞ §@md_str�Base.getindex�§extrema�§Missing�recovery_time‘Ù$6d5c6a84-0415-11eb-3fdf-9355200cb520¡:�¡>�¡!�¦isless�ª@isdefined�§Integer�still_missing‘Ù$43e6e856-0414-11eb-19ca-07358aa8b667£isa�¡<�¤Base�§correct‘Ù$3d88c056-0414-11eb-0025-05d3aff1588b¬keep_working‘Ù$41cefa68-0414-11eb-3bad-6530360d6f68«not_defined‘Ù$3c0528a0-0414-11eb-2f68-a5657ab9e73d¢==�Ù$9cd2bb00-04b1-11eb-1d83-a703907141a7„´precedence_heuristic §cell_idÙ$9cd2bb00-04b1-11eb-1d83-a703907141a7´downstream_cells_map€²upstream_cells_map…«simulations‘Ù$80c2cd88-04b1-11eb-326e-0120a39405ea¡:�¤plot�¥plot!�§nothing�Ù$8a28c56e-04b4-11eb-279c-3b4dfb2a9f9b„´precedence_heuristic §cell_idÙ$8a28c56e-04b4-11eb-279c-3b4dfb2a9f9b´downstream_cells_map€²upstream_cells_mapƒ£bar�°large_experiment‘Ù$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8«frequencies‘Ù$aa6673d4-0417-11eb-32cc-79560896c195Ù$8631a536-0403-11eb-0379-bb2e56927727„´precedence_heuristic §cell_idÙ$8631a536-0403-11eb-0379-bb2e56927727´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$9a13b17c-0403-11eb-024f-9b37e95e211b„´precedence_heuristic §cell_idÙ$9a13b17c-0403-11eb-024f-9b37e95e211b´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$b92f1cec-04ae-11eb-0072-3535d1118494„´precedence_heuristic §cell_idÙ$b92f1cec-04ae-11eb-0072-3535d1118494´downstream_cells_map€²upstream_cells_map‚ªsimulation‘Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9±InfectionRecovery‘Ù$1a654bdc-0421-11eb-2c38-7d35060e2565Ù$5ef5813a-0a46-11eb-00d3-01ec142e3897„´precedence_heuristic §cell_idÙ$5ef5813a-0a46-11eb-00d3-01ec142e3897´downstream_cells_map€²upstream_cells_map€Ù$9a377b32-0403-11eb-2799-e7e59caa6a45„´precedence_heuristic §cell_idÙ$9a377b32-0403-11eb-2799-e7e59caa6a45´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$778ec25c-0403-11eb-3146-1d11c294bb1f„´precedence_heuristic §cell_idÙ$778ec25c-0403-11eb-3146-1d11c294bb1f´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$9611ca24-0403-11eb-3582-b7e3bb243e62„´precedence_heuristic §cell_idÙ$9611ca24-0403-11eb-3582-b7e3bb243e62´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$26f84600-041d-11eb-1856-b12a3e5c1dc7„´precedence_heuristic §cell_idÙ$26f84600-041d-11eb-1856-b12a3e5c1dc7´downstream_cells_map‡·Base.Enums.Base.typemin�·Base.Enums.Base.typemax�¡IšÙ$7c515a7a-04d5-11eb-0f36-4fcebff709d5Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21fÙ$6d480cf0-0425-11eb-18a9-1737455371d7Ù$393041ec-049f-11eb-3089-2faf378445f3Ù$221bc0ac-04aa-11eb-1331-2b16ebc1ee57Ù$9c39974c-04a5-11eb-184d-317eb542452cÙ$759bc42e-04ab-11eb-0ab1-b12e008c02a9Ù$1491a078-04aa-11eb-0106-19a3cf1e94b0Ù$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9¡S—Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21fÙ$6d480cf0-0425-11eb-18a9-1737455371d7Ù$221bc0ac-04aa-11eb-1331-2b16ebc1ee57Ù$9c39974c-04a5-11eb-184d-317eb542452cÙ$759bc42e-04ab-11eb-0ab1-b12e008c02a9Ù$1491a078-04aa-11eb-0106-19a3cf1e94b0Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9¯InfectionStatus’Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2Ù$98beb336-0425-11eb-3886-4f8cfd210288¡R—Ù$7c515a7a-04d5-11eb-0f36-4fcebff709d5Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21fÙ$221bc0ac-04aa-11eb-1331-2b16ebc1ee57Ù$759bc42e-04ab-11eb-0ab1-b12e008c02a9Ù$1491a078-04aa-11eb-0106-19a3cf1e94b0Ù$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9¸Base.Enums.Enums.namemap�²upstream_cells_map‡¤Base�Base.@__doc__�¥@enum�¾Base.Enums.enum_argument_error�¥Enums�²Base.Enums.convert�²Base.Enums.bitcast�Ù$1ca7a8c2-041a-11eb-146a-15b8cdeaea72„´precedence_heuristic §cell_idÙ$1ca7a8c2-041a-11eb-146a-15b8cdeaea72´downstream_cells_map€²upstream_cells_map‚°small_experiment‘Ù$d8abd2f6-0416-11eb-1c2a-f9157d9760a7«frequencies‘Ù$aa6673d4-0417-11eb-32cc-79560896c195Ù$190deebc-0424-11eb-19fe-615997093e14„´precedence_heuristic §cell_idÙ$190deebc-0424-11eb-19fe-615997093e14´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$1a654bdc-0421-11eb-2c38-7d35060e2565„´precedence_heuristic §cell_idÙ$1a654bdc-0421-11eb-2c38-7d35060e2565´downstream_cells_map�±InfectionRecovery™Ù$221bc0ac-04aa-11eb-1331-2b16ebc1ee57Ù$9c39974c-04a5-11eb-184d-317eb542452cÙ$759bc42e-04ab-11eb-0ab1-b12e008c02a9Ù$1491a078-04aa-11eb-0106-19a3cf1e94b0Ù$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272Ù$b92f1cec-04ae-11eb-0072-3535d1118494Ù$2c62b4ae-04b3-11eb-0080-a1035a7e31a2Ù$c5156c72-04af-11eb-1106-b13969b036caÙ$80c2cd88-04b1-11eb-326e-0120a39405ea²upstream_cells_map�±AbstractInfection‘Ù$223933a4-042c-11eb-10d3-852229f25a35Ù$41cefa68-0414-11eb-3bad-6530360d6f68„´precedence_heuristic §cell_idÙ$41cefa68-0414-11eb-3bad-6530360d6f68´downstream_cells_map�¬keep_working˜Ù$b817f466-04d4-11eb-0a26-c1c667f9f7f7Ù$c61f35ea-04d6-11eb-2503-17a79f8d0298Ù$7c515a7a-04d5-11eb-0f36-4fcebff709d5Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21fÙ$393041ec-049f-11eb-3089-2faf378445f3Ù$759bc42e-04ab-11eb-0ab1-b12e008c02a9Ù$1491a078-04aa-11eb-0106-19a3cf1e94b0Ù$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272²upstream_cells_map…§@md_str�³Markdown.Admonition�«Markdown.MD�¨Markdown�¨getindex�Ù$847d0fc2-041d-11eb-2864-79066e223b45„´precedence_heuristic §cell_idÙ$847d0fc2-041d-11eb-2864-79066e223b45´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$77428072-0403-11eb-0068-81e3728f2ebe„´precedence_heuristic §cell_idÙ$77428072-0403-11eb-0068-81e3728f2ebe´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$9a837b52-0425-11eb-231f-a74405ff6e23„´precedence_heuristic §cell_idÙ$9a837b52-0425-11eb-231f-a74405ff6e23´downstream_cells_map�®is_susceptible‘Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21f²upstream_cells_map‚§missing�¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2Ù$0a967f38-0493-11eb-0624-77e40b24d757„´precedence_heuristic §cell_idÙ$0a967f38-0493-11eb-0624-77e40b24d757´downstream_cells_map€²upstream_cells_map…§@md_str�Base.getindex�¤Base�®Base.Docs.HTML�©@html_str�Ù$28db9d98-04ca-11eb-3606-9fb89fa62f36„´precedence_heuristic §cell_idÙ$28db9d98-04ca-11eb-3606-9fb89fa62f36´downstream_cells_map�run_basic_sir‘Ù$c5156c72-04af-11eb-1106-b13969b036ca²upstream_cells_mapˆ¤Core�¤Base�·PlutoRunner.create_bond�«PlutoRunner�¯Core.applicable�¥@bind�¦Button�¨Base.get�Ù$8692bf42-0403-11eb-191f-b7d08895274f„´precedence_heuristic §cell_idÙ$8692bf42-0403-11eb-191f-b7d08895274f´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$da49710e-0420-11eb-092e-4f1173868738„´precedence_heuristic §cell_idÙ$da49710e-0420-11eb-092e-4f1173868738´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$7bb8e426-0495-11eb-3a8b-cbbab61a1631„´precedence_heuristic §cell_idÙ$7bb8e426-0495-11eb-3a8b-cbbab61a1631´downstream_cells_map€²upstream_cells_map‡£exp�°large_experiment‘Ù$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8£bar�¨LinRange�¥plot!�¡*�«frequencies‘Ù$aa6673d4-0417-11eb-32cc-79560896c195Ù$a4c9ccdc-12ca-11eb-072f-e34595520548„´precedence_heuristic §cell_idÙ$a4c9ccdc-12ca-11eb-072f-e34595520548´downstream_cells_map€²upstream_cells_map‰¦length�¦string�£sum�«simulations‘Ù$80c2cd88-04b1-11eb-326e-0120a39405ea£map�¡/�¢|>�¥first�¥round�Ù$21c50840-0435-11eb-1307-7138ecde0691„´precedence_heuristic §cell_idÙ$21c50840-0435-11eb-1307-7138ecde0691´downstream_cells_map€²upstream_cells_map€Ù$2ade2694-0425-11eb-2fb2-390da43d9695„´precedence_heuristic §cell_idÙ$2ade2694-0425-11eb-2fb2-390da43d9695´downstream_cells_map€²upstream_cells_map€Ù$aa6673d4-0417-11eb-32cc-79560896c195„´precedence_heuristic §cell_idÙ$aa6673d4-0417-11eb-32cc-79560896c195´downstream_cells_map�«frequencies”Ù$1ca7a8c2-041a-11eb-146a-15b8cdeaea72Ù$8a28c56e-04b4-11eb-279c-3b4dfb2a9f9bÙ$823364ce-041c-11eb-2467-7ffa4f751527Ù$7bb8e426-0495-11eb-3a8b-cbbab61a1631²upstream_cells_map…¦length�¤Dict�¡/�¡+�£get�Ù$73047bba-0416-11eb-1047-23e9c3dbde05„´precedence_heuristic §cell_idÙ$73047bba-0416-11eb-1047-23e9c3dbde05´downstream_cells_map�¾interpretation_of_p_equals_one�²upstream_cells_map‚§@md_str�¨getindex�Ù$bf6fd176-04cc-11eb-008a-2fb6ff70a9cb„´precedence_heuristic §cell_idÙ$bf6fd176-04cc-11eb-008a-2fb6ff70a9cb´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$43e6e856-0414-11eb-19ca-07358aa8b667„´precedence_heuristic §cell_idÙ$43e6e856-0414-11eb-19ca-07358aa8b667´downstream_cells_map�still_missing”Ù$b817f466-04d4-11eb-0a26-c1c667f9f7f7Ù$c61f35ea-04d6-11eb-2503-17a79f8d0298Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21fÙ$393041ec-049f-11eb-3089-2faf378445f3²upstream_cells_map…§@md_str�³Markdown.Admonition�«Markdown.MD�¨Markdown�¨getindex�Ù$95c598d4-0403-11eb-2328-0175ed564915„´precedence_heuristic §cell_idÙ$95c598d4-0403-11eb-2328-0175ed564915´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$2b26dc42-0403-11eb-205f-cd2c23d8cb03„´precedence_heuristic §cell_idÙ$2b26dc42-0403-11eb-205f-cd2c23d8cb03´downstream_cells_map€²upstream_cells_map�¨bigbreak‘Ù$39dffa3c-0414-11eb-0197-e72b299e9c63Ù$1ac4b33a-0435-11eb-36f8-8f3f81ae7844„´precedence_heuristic §cell_idÙ$1ac4b33a-0435-11eb-36f8-8f3f81ae7844´downstream_cells_map€²upstream_cells_map€Ù$a8dd5cae-0425-11eb-119c-bfcbf832d695„´precedence_heuristic §cell_idÙ$a8dd5cae-0425-11eb-119c-bfcbf832d695´downstream_cells_map�«is_infected‘Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21f²upstream_cells_map‚§missing�¥Agent‘Ù$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2´cell_execution_orderÜ ŽÙ$12cc2940-0403-11eb-19a7-bb570de58f6fÙ$15187690-0403-11eb-2dfd-fd924faa3513Ù$01341648-0403-11eb-2212-db450c299f35Ù$06f30b2a-0403-11eb-0f05-8badebe1011dÙ$095cbf46-0403-11eb-0c37-35de9562cebcÙ$03a85970-0403-11eb-334a-812b59c0905bÙ$107e65a4-0403-11eb-0c14-37d8d828b469Ù$1d3356c4-0403-11eb-0f48-01b5eb14a585Ù$df8547b4-0400-11eb-07c6-fb370b61c2b6Ù$d8797684-0414-11eb-1869-5b1e2c469011Ù$02b0c2fc-0415-11eb-2b40-7bca8ea4eef9Ù$76d117d4-0403-11eb-05d2-c5ea47d06f43Ù$6d5c6a84-0415-11eb-3fdf-9355200cb520Ù$d57c6a5a-041b-11eb-3ab4-774a2d45a891Ù$6db6c894-0415-11eb-305a-c75b119d89e9Ù$6de37d6c-0415-11eb-1b05-85ac820016c7Ù$73047bba-0416-11eb-1047-23e9c3dbde05Ù$76f62d64-0403-11eb-27e2-3de58366b619Ù$cdaade9c-0416-11eb-0550-7b5b3d33e240Ù$c5c7cb86-041b-11eb-3360-45463105f3c9Ù$d8abd2f6-0416-11eb-1c2a-f9157d9760a7Ù$771c8f0c-0403-11eb-097e-ab24d0714ad5Ù$aa6673d4-0417-11eb-32cc-79560896c195Ù$105d347e-041c-11eb-2fc8-1d9e5eda2be0Ù$1ca7a8c2-041a-11eb-146a-15b8cdeaea72Ù$77428072-0403-11eb-0068-81e3728f2ebeÙ$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8Ù$dc784864-0430-11eb-1478-d1153e017310Ù$8a28c56e-04b4-11eb-279c-3b4dfb2a9f9bÙ$9374e63c-0493-11eb-0952-4b97512d7cdbÙ$823364ce-041c-11eb-2467-7ffa4f751527Ù$1ddbaa18-0494-11eb-1fc8-250ab6ae89f1Ù$f3f81172-041c-11eb-2b9b-e99b7b9400edÙ$7768a2dc-0403-11eb-39b7-fd660dc952feÙ$f1f89502-0494-11eb-2303-0b79d8bbd13fÙ$06089d1e-0495-11eb-0ace-a7a7dc60e5b2Ù$77b54c10-0403-11eb-16ad-65374d29a817Ù$bb63f3cc-042f-11eb-04ff-a128aec3c378Ù$bb8aeb58-042f-11eb-18b8-f995631df619Ù$778ec25c-0403-11eb-3146-1d11c294bb1fÙ$3f497394-0a46-11eb-3369-8189905f011cÙ$7bb8e426-0495-11eb-3a8b-cbbab61a1631Ù$5ef5813a-0a46-11eb-00d3-01ec142e3897Ù$5950b37e-0a46-11eb-3480-d5520013692eÙ$77db111e-0403-11eb-2dea-4b42ceed65d6Ù$7335de44-042f-11eb-2873-8bceef722432Ù$61789646-0403-11eb-0042-f3b8308f11baÙ$26f84600-041d-11eb-1856-b12a3e5c1dc7Ù$271ec5f0-041d-11eb-041b-db46ec1465e0Ù$7f4e121c-041d-11eb-0dff-cd0cbfdfd606Ù$7f744644-041d-11eb-08a0-3719cc0adeb7Ù$88c53208-041d-11eb-3b1e-31b57ba99f05Ù$847d0fc2-041d-11eb-2864-79066e223b45Ù$860790fc-0403-11eb-2f2e-355f77dcc7afÙ$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2Ù$ae70625a-041f-11eb-3082-0753419d6d57Ù$60a8b708-04c8-11eb-37b1-3daec644ac90Ù$189cae1e-0424-11eb-2666-65bf297d8bddÙ$18d308c4-0424-11eb-176d-49feec6889cfÙ$190deebc-0424-11eb-19fe-615997093e14Ù$82f2580a-04c8-11eb-1eea-bdb4e50eee3bÙ$8631a536-0403-11eb-0379-bb2e56927727Ù$98beb336-0425-11eb-3886-4f8cfd210288Ù$866299e8-0403-11eb-085d-2b93459cc141Ù$9a837b52-0425-11eb-231f-a74405ff6e23Ù$a8dd5cae-0425-11eb-119c-bfcbf832d695Ù$8692bf42-0403-11eb-191f-b7d08895274fÙ$6d480cf0-0425-11eb-18a9-1737455371d7Ù$7946d83a-04a0-11eb-224b-2b315e87bc84Ù$488771e2-049f-11eb-3b0a-0de260457731Ù$86d98d0a-0403-11eb-215b-c58ad721a90bÙ$223933a4-042c-11eb-10d3-852229f25a35Ù$1a654bdc-0421-11eb-2c38-7d35060e2565Ù$2d3bba2a-04a8-11eb-2c40-87794b6aeeacÙ$221bc0ac-04aa-11eb-1331-2b16ebc1ee57Ù$406aabea-04a5-11eb-06b8-312879457c42Ù$b21475c6-04ac-11eb-1366-f3b5e967402dÙ$9c39974c-04a5-11eb-184d-317eb542452cÙ$619c8a10-0403-11eb-2e89-8b0974fb01d0Ù$8a1d5aea-04ae-11eb-2177-eb37822db4f1Ù$2ade2694-0425-11eb-2fb2-390da43d9695Ù$955321de-0403-11eb-04ce-fb1670dfbb9eÙ$32cea7ba-0429-11eb-06bc-a5f4ae3ffe37Ù$46133a74-04b1-11eb-0b46-0bc74e564680Ù$95771ce2-0403-11eb-3056-f1dc3a8b7ec3Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9Ù$887d27fc-04bc-11eb-0ab9-eb95ef9607f8Ù$b92f1cec-04ae-11eb-0072-3535d1118494Ù$2c62b4ae-04b3-11eb-0080-a1035a7e31a2Ù$28db9d98-04ca-11eb-3606-9fb89fa62f36Ù$c5156c72-04af-11eb-1106-b13969b036caÙ$0a967f38-0493-11eb-0624-77e40b24d757Ù$bf6fd176-04cc-11eb-008a-2fb6ff70a9cbÙ$38b1aa5a-04cf-11eb-11a2-930741fc9076Ù$80c2cd88-04b1-11eb-326e-0120a39405eaÙ$80e6f1e0-04b1-11eb-0d4e-475f1d80c2bbÙ$9cd2bb00-04b1-11eb-1d83-a703907141a7Ù$95c598d4-0403-11eb-2328-0175ed564915Ù$10cf6db8-04b8-11eb-2267-3db6d7f9c89aÙ$843fd63c-04d0-11eb-0113-c58d346179d6Ù$7f635722-04d0-11eb-3209-4b603c9e843cÙ$a4c9ccdc-12ca-11eb-072f-e34595520548Ù$dfb99ace-04cf-11eb-0739-7d694c837d59Ù$1c6aa208-04d1-11eb-0b87-cf429e6ff6d0Ù$95eb9f88-0403-11eb-155b-7b2d3a07cff0Ù$287ee7aa-0435-11eb-0ca3-951dbbe69404Ù$9611ca24-0403-11eb-3582-b7e3bb243e62Ù$26e2978e-0435-11eb-0d61-25f552d2771eÙ$9635c944-0403-11eb-3982-4df509f6a556Ù$4ad11052-042c-11eb-3643-8b2b3e1269bcÙ$61c00724-0403-11eb-228d-17c11670e5d1Ù$8dd97820-04a5-11eb-36c0-8f92d4b859a8Ù$99ef7b2a-0403-11eb-08ef-e1023cd151aeÙ$9a13b17c-0403-11eb-024f-9b37e95e211bÙ$1ac4b33a-0435-11eb-36f8-8f3f81ae7844Ù$9a377b32-0403-11eb-2799-e7e59caa6a45Ù$21c50840-0435-11eb-1307-7138ecde0691Ù$da49710e-0420-11eb-092e-4f1173868738Ù$e6219c7c-0420-11eb-3faa-13126f7c8007Ù$531d13c2-0414-11eb-0acd-4905a684869dÙ$4f19e872-0414-11eb-0dfd-e53d2aecc4dcÙ$48a16c42-0414-11eb-0e0c-bf52bbb0f618Ù$6d906d0c-0415-11eb-0c1c-b5c0aca841dbÙ$08e2bc64-0417-11eb-1457-21c0d18e8c51Ù$9cf9080a-04b1-11eb-12a0-17013f2d37f5Ù$461586dc-0414-11eb-00f3-4984b57bfac5Ù$43e6e856-0414-11eb-19ca-07358aa8b667Ù$41cefa68-0414-11eb-3bad-6530360d6f68Ù$3f5e0af8-0414-11eb-34a7-a71e7aaf6443Ù$3d88c056-0414-11eb-0025-05d3aff1588bÙ$3c0528a0-0414-11eb-2f68-a5657ab9e73dÙ$b817f466-04d4-11eb-0a26-c1c667f9f7f7Ù$c61f35ea-04d6-11eb-2503-17a79f8d0298Ù$7c515a7a-04d5-11eb-0f36-4fcebff709d5Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21fÙ$393041ec-049f-11eb-3089-2faf378445f3Ù$759bc42e-04ab-11eb-0ab1-b12e008c02a9Ù$1491a078-04aa-11eb-0106-19a3cf1e94b0Ù$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272Ù$39dffa3c-0414-11eb-0197-e72b299e9c63Ù$2b26dc42-0403-11eb-205f-cd2c23d8cb03Ù$5689841e-0414-11eb-0492-63c77ddbd136´last_hot_reload_timeË ©shortpathµhw4 some solutions.jl®process_status¥ready¤pathÙK/home/runner/work/disorganised-mess/disorganised-mess/hw4 some solutions.jlpluto_version¨v0.19.47®last_save_timeËAÚ ÌÏôϪcell_orderÜ ŽÙ$01341648-0403-11eb-2212-db450c299f35Ù$03a85970-0403-11eb-334a-812b59c0905bÙ$06f30b2a-0403-11eb-0f05-8badebe1011dÙ$095cbf46-0403-11eb-0c37-35de9562cebcÙ$107e65a4-0403-11eb-0c14-37d8d828b469Ù$12cc2940-0403-11eb-19a7-bb570de58f6fÙ$15187690-0403-11eb-2dfd-fd924faa3513Ù$1d3356c4-0403-11eb-0f48-01b5eb14a585Ù$2b26dc42-0403-11eb-205f-cd2c23d8cb03Ù$df8547b4-0400-11eb-07c6-fb370b61c2b6Ù$d8797684-0414-11eb-1869-5b1e2c469011Ù$02b0c2fc-0415-11eb-2b40-7bca8ea4eef9Ù$b817f466-04d4-11eb-0a26-c1c667f9f7f7Ù$76d117d4-0403-11eb-05d2-c5ea47d06f43Ù$6d5c6a84-0415-11eb-3fdf-9355200cb520Ù$d57c6a5a-041b-11eb-3ab4-774a2d45a891Ù$c61f35ea-04d6-11eb-2503-17a79f8d0298Ù$6d906d0c-0415-11eb-0c1c-b5c0aca841dbÙ$6db6c894-0415-11eb-305a-c75b119d89e9Ù$6de37d6c-0415-11eb-1b05-85ac820016c7Ù$73047bba-0416-11eb-1047-23e9c3dbde05Ù$76f62d64-0403-11eb-27e2-3de58366b619Ù$cdaade9c-0416-11eb-0550-7b5b3d33e240Ù$c5c7cb86-041b-11eb-3360-45463105f3c9Ù$d8abd2f6-0416-11eb-1c2a-f9157d9760a7Ù$771c8f0c-0403-11eb-097e-ab24d0714ad5Ù$aa6673d4-0417-11eb-32cc-79560896c195Ù$105d347e-041c-11eb-2fc8-1d9e5eda2be0Ù$1ca7a8c2-041a-11eb-146a-15b8cdeaea72Ù$08e2bc64-0417-11eb-1457-21c0d18e8c51Ù$77428072-0403-11eb-0068-81e3728f2ebeÙ$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8Ù$dc784864-0430-11eb-1478-d1153e017310Ù$8a28c56e-04b4-11eb-279c-3b4dfb2a9f9bÙ$9374e63c-0493-11eb-0952-4b97512d7cdbÙ$823364ce-041c-11eb-2467-7ffa4f751527Ù$1ddbaa18-0494-11eb-1fc8-250ab6ae89f1Ù$f3f81172-041c-11eb-2b9b-e99b7b9400edÙ$7768a2dc-0403-11eb-39b7-fd660dc952feÙ$f1f89502-0494-11eb-2303-0b79d8bbd13fÙ$06089d1e-0495-11eb-0ace-a7a7dc60e5b2Ù$77b54c10-0403-11eb-16ad-65374d29a817Ù$bb63f3cc-042f-11eb-04ff-a128aec3c378Ù$bb8aeb58-042f-11eb-18b8-f995631df619Ù$778ec25c-0403-11eb-3146-1d11c294bb1fÙ$3f497394-0a46-11eb-3369-8189905f011cÙ$7bb8e426-0495-11eb-3a8b-cbbab61a1631Ù$5ef5813a-0a46-11eb-00d3-01ec142e3897Ù$5950b37e-0a46-11eb-3480-d5520013692eÙ$77db111e-0403-11eb-2dea-4b42ceed65d6Ù$7335de44-042f-11eb-2873-8bceef722432Ù$61789646-0403-11eb-0042-f3b8308f11baÙ$26f84600-041d-11eb-1856-b12a3e5c1dc7Ù$271ec5f0-041d-11eb-041b-db46ec1465e0Ù$7f4e121c-041d-11eb-0dff-cd0cbfdfd606Ù$7f744644-041d-11eb-08a0-3719cc0adeb7Ù$88c53208-041d-11eb-3b1e-31b57ba99f05Ù$847d0fc2-041d-11eb-2864-79066e223b45Ù$860790fc-0403-11eb-2f2e-355f77dcc7afÙ$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2Ù$ae70625a-041f-11eb-3082-0753419d6d57Ù$60a8b708-04c8-11eb-37b1-3daec644ac90Ù$189cae1e-0424-11eb-2666-65bf297d8bddÙ$18d308c4-0424-11eb-176d-49feec6889cfÙ$190deebc-0424-11eb-19fe-615997093e14Ù$82f2580a-04c8-11eb-1eea-bdb4e50eee3bÙ$8631a536-0403-11eb-0379-bb2e56927727Ù$98beb336-0425-11eb-3886-4f8cfd210288Ù$7c515a7a-04d5-11eb-0f36-4fcebff709d5Ù$866299e8-0403-11eb-085d-2b93459cc141Ù$9a837b52-0425-11eb-231f-a74405ff6e23Ù$a8dd5cae-0425-11eb-119c-bfcbf832d695Ù$c4a8694a-04d4-11eb-1eef-c9e037e6b21fÙ$8692bf42-0403-11eb-191f-b7d08895274fÙ$6d480cf0-0425-11eb-18a9-1737455371d7Ù$7946d83a-04a0-11eb-224b-2b315e87bc84Ù$488771e2-049f-11eb-3b0a-0de260457731Ù$393041ec-049f-11eb-3089-2faf378445f3Ù$86d98d0a-0403-11eb-215b-c58ad721a90bÙ$223933a4-042c-11eb-10d3-852229f25a35Ù$1a654bdc-0421-11eb-2c38-7d35060e2565Ù$2d3bba2a-04a8-11eb-2c40-87794b6aeeacÙ$221bc0ac-04aa-11eb-1331-2b16ebc1ee57Ù$406aabea-04a5-11eb-06b8-312879457c42Ù$b21475c6-04ac-11eb-1366-f3b5e967402dÙ$9c39974c-04a5-11eb-184d-317eb542452cÙ$759bc42e-04ab-11eb-0ab1-b12e008c02a9Ù$1491a078-04aa-11eb-0106-19a3cf1e94b0Ù$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272Ù$619c8a10-0403-11eb-2e89-8b0974fb01d0Ù$8a1d5aea-04ae-11eb-2177-eb37822db4f1Ù$2ade2694-0425-11eb-2fb2-390da43d9695Ù$955321de-0403-11eb-04ce-fb1670dfbb9eÙ$32cea7ba-0429-11eb-06bc-a5f4ae3ffe37Ù$46133a74-04b1-11eb-0b46-0bc74e564680Ù$95771ce2-0403-11eb-3056-f1dc3a8b7ec3Ù$3d3b672c-0426-11eb-0a36-153ce3c276b9Ù$887d27fc-04bc-11eb-0ab9-eb95ef9607f8Ù$b92f1cec-04ae-11eb-0072-3535d1118494Ù$2c62b4ae-04b3-11eb-0080-a1035a7e31a2Ù$c5156c72-04af-11eb-1106-b13969b036caÙ$28db9d98-04ca-11eb-3606-9fb89fa62f36Ù$0a967f38-0493-11eb-0624-77e40b24d757Ù$bf6fd176-04cc-11eb-008a-2fb6ff70a9cbÙ$38b1aa5a-04cf-11eb-11a2-930741fc9076Ù$80c2cd88-04b1-11eb-326e-0120a39405eaÙ$80e6f1e0-04b1-11eb-0d4e-475f1d80c2bbÙ$9cd2bb00-04b1-11eb-1d83-a703907141a7Ù$9cf9080a-04b1-11eb-12a0-17013f2d37f5Ù$95c598d4-0403-11eb-2328-0175ed564915Ù$10cf6db8-04b8-11eb-2267-3db6d7f9c89aÙ$843fd63c-04d0-11eb-0113-c58d346179d6Ù$7f635722-04d0-11eb-3209-4b603c9e843cÙ$a4c9ccdc-12ca-11eb-072f-e34595520548Ù$dfb99ace-04cf-11eb-0739-7d694c837d59Ù$1c6aa208-04d1-11eb-0b87-cf429e6ff6d0Ù$95eb9f88-0403-11eb-155b-7b2d3a07cff0Ù$287ee7aa-0435-11eb-0ca3-951dbbe69404Ù$9611ca24-0403-11eb-3582-b7e3bb243e62Ù$26e2978e-0435-11eb-0d61-25f552d2771eÙ$9635c944-0403-11eb-3982-4df509f6a556Ù$4ad11052-042c-11eb-3643-8b2b3e1269bcÙ$61c00724-0403-11eb-228d-17c11670e5d1Ù$8dd97820-04a5-11eb-36c0-8f92d4b859a8Ù$99ef7b2a-0403-11eb-08ef-e1023cd151aeÙ$9a13b17c-0403-11eb-024f-9b37e95e211bÙ$1ac4b33a-0435-11eb-36f8-8f3f81ae7844Ù$9a377b32-0403-11eb-2799-e7e59caa6a45Ù$21c50840-0435-11eb-1307-7138ecde0691Ù$da49710e-0420-11eb-092e-4f1173868738Ù$e6219c7c-0420-11eb-3faa-13126f7c8007Ù$5689841e-0414-11eb-0492-63c77ddbd136Ù$531d13c2-0414-11eb-0acd-4905a684869dÙ$4f19e872-0414-11eb-0dfd-e53d2aecc4dcÙ$48a16c42-0414-11eb-0e0c-bf52bbb0f618Ù$461586dc-0414-11eb-00f3-4984b57bfac5Ù$43e6e856-0414-11eb-19ca-07358aa8b667Ù$41cefa68-0414-11eb-3bad-6530360d6f68Ù$3f5e0af8-0414-11eb-34a7-a71e7aaf6443Ù$3d88c056-0414-11eb-0025-05d3aff1588bÙ$3c0528a0-0414-11eb-2f68-a5657ab9e73dÙ$39dffa3c-0414-11eb-0197-e72b299e9c63±published_objects€¥nbpkgНinstall_time_nsÀ¬instantiatedòinstalled_versions€°terminal_outputs€§enabled·restart_recommended_msgÀ´restart_required_msgÀbusy_packages�¶waiting_for_permissionÂÙ,waiting_for_permission_but_probably_disabled«cell_inputsÞ ŽÙ$f1f89502-0494-11eb-2303-0b79d8bbd13f„§cell_idÙ$f1f89502-0494-11eb-2303-0b79d8bbd13f¤codeÙ‚function frequencies_plot_with_mean(data)
# start out by copying the frequencies_plot_with_maximum function
return missing
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$95771ce2-0403-11eb-3056-f1dc3a8b7ec3„§cell_idÙ$95771ce2-0403-11eb-3056-f1dc3a8b7ec3¤codeÚ:md"""
👉 Write a function `simulation` that does the following:
1. Generate the $N$ agents.
2. Run `sweep!` a number $T$ of times. Calculate and store the total number of agents with each status at each step in variables `S_counts`, `I_counts` and `R_counts`.
3. Return the vectors `S_counts`, `I_counts` and `R_counts` in a **named tuple**, with keys `S`, `I` and `R`.
You've seen an example of named tuples before: the `student` variable at the top of the notebook!
_Feel free to store the counts in a different way, as long as the return type is the same._
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$e6219c7c-0420-11eb-3faa-13126f7c8007„§cell_idÙ$e6219c7c-0420-11eb-3faa-13126f7c8007¤codeÙzlines_i_edited = md"""
Abstraction, lines 1-219
Array Basics, lines 1-137
Course Intro, lines 1-44
(_for example_)
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$b817f466-04d4-11eb-0a26-c1c667f9f7f7„§cell_idÙ$b817f466-04d4-11eb-0a26-c1c667f9f7f7¤codeÚgif !@isdefined(bernoulli)
not_defined(:bernoulli)
else
let
result = bernoulli(0.5)
if result isa Missing
still_missing()
elseif !(result isa Bool)
keep_working(md"Make sure that you return either `true` or `false`.")
else
if bernoulli(0.0) == false && bernoulli(1.0) == true
correct()
else
keep_working()
end
end
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$08e2bc64-0417-11eb-1457-21c0d18e8c51„§cell_idÙ$08e2bc64-0417-11eb-1457-21c0d18e8c51¤codeÚhint(md"""
Do you remember how we worked with dictionaries in Homework 3? You can create an empty dictionary using `Dict()`. You may want to use either the function `haskey` or the function `get` on your dictionary -- check the documentation for how to use these functions.
""")¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$bb8aeb58-042f-11eb-18b8-f995631df619„§cell_idÙ$bb8aeb58-042f-11eb-18b8-f995631df619¤codeÙxmd"""
As you separately vary $p$ and $N$, what do you observe about the **mean** in each case? Does that make sense?
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$223933a4-042c-11eb-10d3-852229f25a35„§cell_idÙ$223933a4-042c-11eb-10d3-852229f25a35¤codeÙ#abstract type AbstractInfection end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2„§cell_idÙ$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2¤codeÙFmutable struct Agent
status::InfectionStatus
num_infected::Int64
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$7f635722-04d0-11eb-3209-4b603c9e843c„§cell_idÙ$7f635722-04d0-11eb-3209-4b603c9e843c¤codeºsir_mean_plot(simulations)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$7c515a7a-04d5-11eb-0f36-4fcebff709d5„§cell_idÙ$7c515a7a-04d5-11eb-0f36-4fcebff709d5¤codeÙ¿if !@isdefined(set_status!)
not_defined(:set_status!)
else
let
agent = Agent(I,2)
set_status!(agent, R)
if agent.status == R
correct()
else
keep_working()
end
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$107e65a4-0403-11eb-0c14-37d8d828b469„§cell_idÙ$107e65a4-0403-11eb-0c14-37d8d828b469¤codeÙ)md"_Let's create a package environment:_"¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$1c6aa208-04d1-11eb-0b87-cf429e6ff6d0„§cell_idÙ$1c6aa208-04d1-11eb-0b87-cf429e6ff6d0¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$80e6f1e0-04b1-11eb-0d4e-475f1d80c2bb„§cell_idÙ$80e6f1e0-04b1-11eb-0d4e-475f1d80c2bb¤codeÙÐmd"""
In the cell below, we plot the evolution of the number of $I$ individuals as a function of time for each of the simulations on the same plot using transparency (`alpha=0.5` inside the plot command).
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$7f4e121c-041d-11eb-0dff-cd0cbfdfd606„§cell_idÙ$7f4e121c-041d-11eb-0dff-cd0cbfdfd606¤codeµtest_status = missing¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$3d3b672c-0426-11eb-0a36-153ce3c276b9„§cell_idÙ$3d3b672c-0426-11eb-0a36-153ce3c276b9¤codeÚ•function simulation(N::Integer, T::Integer, infection::AbstractInfection)
agents = generate_agents(N)
S_counts = []
I_counts = []
R_counts = []
for _ in 1:T
push!(S_counts, sum(a -> a.status == S, agents))
push!(I_counts, sum(a -> a.status == I, agents))
push!(R_counts, sum(a -> a.status == R, agents))
sweep!(agents, infection)
end
return (S=S_counts, I=I_counts, R=R_counts)
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$4f19e872-0414-11eb-0dfd-e53d2aecc4dc„§cell_idÙ$4f19e872-0414-11eb-0dfd-e53d2aecc4dc¤codeÙImd"## Function library
Just some helper functions used in the notebook."¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$759bc42e-04ab-11eb-0ab1-b12e008c02a9„§cell_idÙ$759bc42e-04ab-11eb-0ab1-b12e008c02a9¤codeÚ/if !@isdefined(interact!)
not_defined(:interact!)
else
let
agent = Agent(S, 9)
source = Agent(I, 0)
interact!(agent, source, InfectionRecovery(0.0, 1.0))
if source.status != I || source.num_infected != 0
keep_working(md"The `source` should not be modified if no infection occured.")
elseif agent.status != S
keep_working(md"The `agent` should get infected with the right probability.")
else
agent = Agent(S, 9)
source = Agent(S, 0)
interact!(agent, source, InfectionRecovery(1.0, 1.0))
if source.status != S || source.num_infected != 0 || agent.status != S
keep_working(md"The `agent` should get infected with the right probability if the source is infectious.")
else
agent = Agent(S, 9)
source = Agent(I, 3)
interact!(agent, source, InfectionRecovery(1.0, 1.0))
if agent.status == R
almost(md"The agent should not recover immediately after becoming infectious.")
elseif agent.status == S
keep_working(md"The `agent` should recover from an infectious state with the right probability.")
elseif source.status != I || source.num_infected != 4
almost(md"The `source` did not get updated correctly after infecting the `agent`.")
else
correct(md"Your function treats the **susceptible** agent case correctly!")
end
end
end
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$5689841e-0414-11eb-0492-63c77ddbd136„§cell_idÙ$5689841e-0414-11eb-0492-63c77ddbd136¤code¨bigbreak¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$99ef7b2a-0403-11eb-08ef-e1023cd151ae„§cell_idÙ$99ef7b2a-0403-11eb-08ef-e1023cd151ae¤codeÚJmd"""
👉 Make a *new method* for the `interact!` function that accepts the new infection type as argument, reusing as much functionality as possible from the previous version.
Write it in the same cell as [our previous `interact!` method](#interactfunction), and use a `begin` block to group the two definitions together.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$77b54c10-0403-11eb-16ad-65374d29a817„§cell_idÙ$77b54c10-0403-11eb-16ad-65374d29a817¤codeÚmd"""
👉 Write an interactive visualization that draws the histogram and mean for $p$ between $0.01$ (not $0$!) and $1$, and $N$ between $1$ and $100,000$, say. To avoid a naming conflict, call them `p_interactive` and `N_interactive`, instead of just `p` and `N`.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$7768a2dc-0403-11eb-39b7-fd660dc952fe„§cell_idÙ$7768a2dc-0403-11eb-39b7-fd660dc952fe¤codeÙ�md"""
👉 Write the function `frequencies_plot_with_mean` that calculates the mean recovery time and displays it using a vertical line.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$60a8b708-04c8-11eb-37b1-3daec644ac90„§cell_idÙ$60a8b708-04c8-11eb-37b1-3daec644ac90¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$95eb9f88-0403-11eb-155b-7b2d3a07cff0„§cell_idÙ$95eb9f88-0403-11eb-155b-7b2d3a07cff0¤codeÚomd"""
👉 Write a function `sir_mean_error_plot` that does the same as `sir_mean_plot`, which also computes the **standard deviation** $\sigma$ of $S$, $I$, $R$ at each step. Add this to the plot using **error bars**, using the option `yerr=σ` in the plot command; use transparency.
This should confirm that the distribution of $I$ at each step is pretty wide!
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$955321de-0403-11eb-04ce-fb1670dfbb9e„§cell_idÙ$955321de-0403-11eb-04ce-fb1670dfbb9e¤codeÙÙmd"""
👉 Write a function `sweep!`. It runs `step!` $N$ times, where $N$ is the number of agents. Thus each agent acts, on average, once per sweep; a sweep is thus the unit of time in our Monte Carlo simulation.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$ae70625a-041f-11eb-3082-0753419d6d57„§cell_idÙ$ae70625a-041f-11eb-3082-0753419d6d57¤codeÚImd"""
When you define a new type like this, Julia automatically defines one or more **constructors**, which are methods of a generic function with the *same name* as the type. These are used to create objects of that type.
👉 Use the `methods` function to check how many constructors are pre-defined for the `Agent` type.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$843fd63c-04d0-11eb-0113-c58d346179d6„§cell_idÙ$843fd63c-04d0-11eb-0113-c58d346179d6¤codeÙ¼# function sir_mean_plot(simulations::Vector{<:NamedTuple})
# # you might need T for this function, here's a trick to get it:
# T = length(first(simulations).S)
# return missing
# end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$189cae1e-0424-11eb-2666-65bf297d8bdd„§cell_idÙ$189cae1e-0424-11eb-2666-65bf297d8bdd¤codeÙZmd"""
👉 Create an agent `test_agent` with status `S` and `num_infected` equal to 0.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$7f744644-041d-11eb-08a0-3719cc0adeb7„§cell_idÙ$7f744644-041d-11eb-08a0-3719cc0adeb7¤codeÙKmd"""
👉 Use the `typeof` function to find the type of `test_status`.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$488771e2-049f-11eb-3b0a-0de260457731„§cell_idÙ$488771e2-049f-11eb-3b0a-0de260457731¤code²generate_agents(3)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$393041ec-049f-11eb-3089-2faf378445f3„§cell_idÙ$393041ec-049f-11eb-3089-2faf378445f3¤codeÚ*if !@isdefined(generate_agents)
not_defined(:generate_agents)
else
let
result = generate_agents(4)
if result isa Missing
still_missing()
elseif result isa Nothing
keep_working("The function returned `nothing`. Did you forget to return something?")
elseif !(result isa Vector) || !all(x -> x isa Agent, result)
keep_working(md"Make sure that you return an array of objects of the type `Agent`.")
elseif length(result) != 4
almost(md"Make sure that you return `N` agents.")
elseif length(Set(result)) != 4
almost(md"You returned the **same** agent `N` times. You need to call the `Agent` constructor `N` times, not once.")
else
if sum(a -> a.status == I, result) != 1
almost(md"Exactly one of the agents should be infectious.")
else
correct()
end
end
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$531d13c2-0414-11eb-0acd-4905a684869d„§cell_idÙ$531d13c2-0414-11eb-0acd-4905a684869d¤codeÙ¦if student.name == "Jazzy Doe"
md"""
!!! danger "Before you submit"
Remember to fill in your **name** and **Kerberos ID** at the top of this notebook.
"""
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$221bc0ac-04aa-11eb-1331-2b16ebc1ee57„§cell_idÙ$221bc0ac-04aa-11eb-1331-2b16ebc1ee57¤codeÚ‹begin
function interact!(agent::Agent, source::Agent, infection::InfectionRecovery)
if agent.status == S && source.status == I
if bernoulli(infection.p_infection)
agent.status = I
source.num_infected += 1
end
elseif agent.status == I
if bernoulli(infection.p_recovery)
agent.status = R
end
end
end
function interact!(agent::Agent, source::Agent, infection::Reinfection)
if agent.status == S && source.status == I
if bernoulli(infection.p_infection)
agent.status = I
source.num_infected += 1
end
elseif agent.status == I
if bernoulli(infection.p_recovery)
agent.status = S
end
end
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$32cea7ba-0429-11eb-06bc-a5f4ae3ffe37„§cell_idÙ$32cea7ba-0429-11eb-06bc-a5f4ae3ffe37¤codeÙyfunction sweep!(agents::Vector{Agent}, infection::AbstractInfection)
for _ in agents
step!(agents, infection)
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$06f30b2a-0403-11eb-0f05-8badebe1011d„§cell_idÙ$06f30b2a-0403-11eb-0f05-8badebe1011d¤codeÚmd"""
# **Homework 4**: _Epidemic modeling I_
`18.S191`, fall 2020
This notebook contains _built-in, live answer checks_! In some exercises you will see a coloured box, which runs a test case on your code, and provides feedback based on the result. Simply edit the code, run it, and the check runs again.
_For MIT students:_ there will also be some additional (secret) test cases that will be run as part of the grading process, and we will look at your notebook and write comments.
Feel free to ask questions!
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$9c39974c-04a5-11eb-184d-317eb542452c„§cell_idÙ$9c39974c-04a5-11eb-184d-317eb542452c¤codeÙ¢let
agent = Agent(S, 0)
source = Agent(I, 0)
infection = InfectionRecovery(0.9, 0.5)
interact!(agent, source, infection)
(agent=agent, source=source)
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$1ddbaa18-0494-11eb-1fc8-250ab6ae89f1„§cell_idÙ$1ddbaa18-0494-11eb-1fc8-250ab6ae89f1¤codeÙ/frequencies_plot_with_maximum(large_experiment)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$06089d1e-0495-11eb-0ace-a7a7dc60e5b2„§cell_idÙ$06089d1e-0495-11eb-0ace-a7a7dc60e5b2¤codeÙ,frequencies_plot_with_mean(large_experiment)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$15187690-0403-11eb-2dfd-fd924faa3513„§cell_idÙ$15187690-0403-11eb-2dfd-fd924faa3513¤codeÙPbegin
Pkg.add(["Plots", "PlutoUI",])
using Plots
plotly()
using PlutoUI
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$d8abd2f6-0416-11eb-1c2a-f9157d9760a7„§cell_idÙ$d8abd2f6-0416-11eb-1c2a-f9157d9760a7¤codeÙ)small_experiment = do_experiment(0.5, 20)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$9374e63c-0493-11eb-0952-4b97512d7cdb„§cell_idÙ$9374e63c-0493-11eb-0952-4b97512d7cdb¤codeÚ*md"""
Great! Feel free to experiment with this function, try giving it a different array as argument. Plots.jl is pretty clever, it even works with an array of strings!
#### Exercise 1.4
Next, we want to **add a new element** to our plot: a vertical line. To demonstrate how this works, here we added a vertical line at the _maximum value_.
To write this function, we first create a **base plot**, we then **modify** that plot to add the vertical line, and finally, we **return** the plot. More on this in [the next info box](#note_about_plotting).
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$2d3bba2a-04a8-11eb-2c40-87794b6aeeac„§cell_idÙ$2d3bba2a-04a8-11eb-2c40-87794b6aeeac¤codeÚˆmd"""
#### Exercise 2.5
👉 Write a function `interact!` that takes an affected `agent` of type `Agent`, an `source` of type `Agent` and an `infection` of type `InfectionRecovery`. It implements a single (one-sided) interaction between two agents:
- If the `agent` is susceptible and the `source` is infectious, then the `source` infects our `agent` with the given infection probability. If the `source` successfully infects the other agent, then its `num_infected` record must be updated.
- If the `agent` is infected then it recovers with the relevant probability.
- Otherwise, nothing happens.
$(html" ")
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$10cf6db8-04b8-11eb-2267-3db6d7f9c89a„§cell_idÙ$10cf6db8-04b8-11eb-2267-3db6d7f9c89a¤codeÚófunction sir_mean_plot(simulations::Vector{<:NamedTuple})
T = length(first(simulations).S)
all_S_counts = map(result -> result.S, simulations)
all_I_counts = map(result -> result.I, simulations)
all_R_counts = map(result -> result.R, simulations)
p = plot()
plot!(p, 1:T, sum(all_S_counts) ./ length(simulations), lw=5, label="S")
plot!(p, 1:T, sum(all_I_counts) ./ length(simulations), lw=5, label="I")
plot!(p, 1:T, sum(all_R_counts) ./ length(simulations), lw=5, label="R")
p
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$dfb99ace-04cf-11eb-0739-7d694c837d59„§cell_idÙ$dfb99ace-04cf-11eb-0739-7d694c837d59¤codeÙ£md"""
👉 Allow $p_\text{infection}$ and $p_\text{recovery}$ to be changed interactively and find parameter values for which you observe an epidemic outbreak.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$271ec5f0-041d-11eb-041b-db46ec1465e0„§cell_idÙ$271ec5f0-041d-11eb-041b-db46ec1465e0¤codeÙämd"""
We have just defined a new type `InfectionStatus`, as well as names `S`, `I` and `R` that are the (only) possible values that a variable of this type can take.
👉 Define a variable `test_status` whose value is `S`.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$7946d83a-04a0-11eb-224b-2b315e87bc84„§cell_idÙ$7946d83a-04a0-11eb-224b-2b315e87bc84¤codeÙ@# function generate_agents(N::Integer)
# return missing
# end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$02b0c2fc-0415-11eb-2b40-7bca8ea4eef9„§cell_idÙ$02b0c2fc-0415-11eb-2b40-7bca8ea4eef9¤codeÙ9# function bernoulli(p::Number)
# return missing
# end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$9635c944-0403-11eb-3982-4df509f6a556„§cell_idÙ$9635c944-0403-11eb-3982-4df509f6a556¤codeÙàmd"""
#### Exercse 3.4
👉 What are three *simple* ways in which you could characterise the magnitude (size) of the epidemic outbreak? Find approximate values of these quantities for one of the runs of your simulation.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$f3f81172-041c-11eb-2b9b-e99b7b9400ed„§cell_idÙ$f3f81172-041c-11eb-2b9b-e99b7b9400ed¤codeÚ+md"""
$(html" ")
> ### Note about plotting
>
> Plots.jl has an interesting property: a plot is an object, not an action. Functions like `plot`, `bar`, `histogram` don't draw anything on your screen - they just return a `Plots.Plot`. This is a struct that contains the _description_ of a plot (what data should be plotted in what way?), not the _picture_.
>
> So a Pluto cell with a single line, `plot(1:10)`, will show a plot, because the _result_ of the function `plot` is a `Plot` object, and Pluto just shows the result of a cell.
>
> ##### Modifying plots
> Nice plots are often formed by overlaying multiple plots. In Plots.jl, this is done using the **modifying functions**: `plot!`, `bar!`, `vline!`, etc. These take an extra (first) argument: a previous plot to modify.
>
> For example, to plot the `sin`, `cos` and `tan` functions in the same view, we do:
> ```julia
> function sin_cos_plot()
> T = -1.0:0.01:1.0
>
> result = plot(T, sin.(T))
> plot!(result, T, cos.(T))
> plot!(result, T, tan.(T))
>
> return result
> end
> ```
>
> 💡 This example demonstrates a useful pattern to combine plots:
> 1. Create a **new** plot and store it in a variable
> 2. **Modify** that plot to add more elements
> 3. Return the plot
>
> It is recommended that these 3 steps happen **within a single cell**. This can prevent some strange glitches when re-running cells. There are three ways to group expressions together into a single cell: `begin`, `let` and `function`. More on this [later](#function_begin_let)!
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$8a1d5aea-04ae-11eb-2177-eb37822db4f1„§cell_idÙ$8a1d5aea-04ae-11eb-2177-eb37822db4f1¤codeÙyfunction step!(agents::Vector{Agent}, infection::AbstractInfection)
interact!(rand(agents), rand(agents), infection)
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$4ad11052-042c-11eb-3643-8b2b3e1269bc„§cell_idÙ$4ad11052-042c-11eb-3643-8b2b3e1269bc¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$76d117d4-0403-11eb-05d2-c5ea47d06f43„§cell_idÙ$76d117d4-0403-11eb-05d2-c5ea47d06f43¤codeÙjmd"""
👉 Write a function `recovery_time(p)` that returns the time taken until the person recovers.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$095cbf46-0403-11eb-0c37-35de9562cebc„§cell_idÙ$095cbf46-0403-11eb-0c37-35de9562cebc¤codeÚ# edit the code below to set your name and kerberos ID (i.e. email without @mit.edu)
student = (name = "Jazzy Doe", kerberos_id = "jazz")
# you might need to wait until all other cells in this notebook have completed running.
# scroll around the page to see what's up¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$6d5c6a84-0415-11eb-3fdf-9355200cb520„§cell_idÙ$6d5c6a84-0415-11eb-3fdf-9355200cb520¤codeÙÎfunction recovery_time(p)
if p ≤ 0
throw(ArgumentError("p must be positive: p = 0 cannot result in a recovery"))
end
recovered = bernoulli(p)
if recovered
1
else
1 + recovery_time(p)
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$26e2978e-0435-11eb-0d61-25f552d2771e„§cell_idÙ$26e2978e-0435-11eb-0d61-25f552d2771e¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$6de37d6c-0415-11eb-1b05-85ac820016c7„§cell_idÙ$6de37d6c-0415-11eb-1b05-85ac820016c7¤codeÙ'md"""
👉 What happens for $p=1$?
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$18d308c4-0424-11eb-176d-49feec6889cf„§cell_idÙ$18d308c4-0424-11eb-176d-49feec6889cf¤code´test_agent = missing¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$46133a74-04b1-11eb-0b46-0bc74e564680„§cell_idÙ$46133a74-04b1-11eb-0b46-0bc74e564680¤codeÙN# function sweep!(agents::Vector{Agent}, infection::AbstractInfection)
# end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$771c8f0c-0403-11eb-097e-ab24d0714ad5„§cell_idÙ$771c8f0c-0403-11eb-097e-ab24d0714ad5¤codeÚ7md"""
#### Exercise 1.3
👉 Write a function `frequencies(data)` that calculates and returns the frequencies (i.e. probability distribution) of input data.
The input will be an array of integers, **with duplicates**, and the result will be a dictionary that maps each occured value to its frequency in the data.
For example,
```julia
frequencies([7, 8, 9, 7])
```
should give
```julia
Dict(
7 => 0.5,
8 => 0.25,
9 => 0.25
)
```
As with any probability distribution, it should be normalised to $1$, in the sense that the *total* probability should be $1$.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$3f497394-0a46-11eb-3369-8189905f011c„§cell_idÙ$3f497394-0a46-11eb-3369-8189905f011c¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$80c2cd88-04b1-11eb-326e-0120a39405ea„§cell_idÙ$80c2cd88-04b1-11eb-326e-0120a39405ea¤codeÙOsimulations = repeat_simulations(100, 1000, InfectionRecovery(0.02, 0.002), 20)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$105d347e-041c-11eb-2fc8-1d9e5eda2be0„§cell_idÙ$105d347e-041c-11eb-2fc8-1d9e5eda2be0¤codeÙ8# function frequencies(values)
# return missing
# end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$2c62b4ae-04b3-11eb-0080-a1035a7e31a2„§cell_idÙ$2c62b4ae-04b3-11eb-0080-a1035a7e31a2¤codeÙ4simulation(100, 1000, InfectionRecovery(0.005, 0.2))¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$6db6c894-0415-11eb-305a-c75b119d89e9„§cell_idÙ$6db6c894-0415-11eb-305a-c75b119d89e9¤codeÚDmd"""
We should always be aware of special cases (sometimes called "boundary conditions"). Make sure *not* to run the code with $p=0$! What would happen in that case? Your code should check for this and throw an `ArgumentError` as follows:
```julia
throw(ArgumentError("..."))
```
with a suitable error message.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$77db111e-0403-11eb-2dea-4b42ceed65d6„§cell_idÙ$77db111e-0403-11eb-2dea-4b42ceed65d6¤codeÙ¾md"""
#### Exercise 1.6
👉 Use $N = 10,000$ to calculate the mean time $\langle \tau(p) \rangle$ to recover as a function of $p$ between $0.001$ and $1$ (say). Plot this relationship.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$6d480cf0-0425-11eb-18a9-1737455371d7„§cell_idÙ$6d480cf0-0425-11eb-18a9-1737455371d7¤codeÙnfunction generate_agents(N::Integer)
agents = [Agent(S, 0) for _ in 1:N]
rand(agents).status = I
agents
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$287ee7aa-0435-11eb-0ca3-951dbbe69404„§cell_idÙ$287ee7aa-0435-11eb-0ca3-951dbbe69404¤codeÙ¸function sir_mean_error_plot(simulations::Vector{<:NamedTuple})
# you might need T for this function, here's a trick to get it:
T = length(first(simulations).S)
return missing
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$3d88c056-0414-11eb-0025-05d3aff1588b„§cell_idÙ$3d88c056-0414-11eb-0025-05d3aff1588b¤codeÙYcorrect(text=rand(yays)) = Markdown.MD(Markdown.Admonition("correct", "Got it!", [text]))¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$03a85970-0403-11eb-334a-812b59c0905b„§cell_idÙ$03a85970-0403-11eb-334a-812b59c0905b¤codeÙPmd"""
Submission by: **_$(student.name)_** ($(student.kerberos_id)@mit.edu)
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$6d906d0c-0415-11eb-0c1c-b5c0aca841db„§cell_idÙ$6d906d0c-0415-11eb-0c1c-b5c0aca841db¤codeÙ{hint(md"Remember to always re-use work you have done previously: in this case you should re-use the function `bernoulli`.")¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$866299e8-0403-11eb-085d-2b93459cc141„§cell_idÙ$866299e8-0403-11eb-085d-2b93459cc141¤codeÙ‰md"""
👉 We will also need functions `is_susceptible` and `is_infected` that check if a given agent is in those respective states.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$461586dc-0414-11eb-00f3-4984b57bfac5„§cell_idÙ$461586dc-0414-11eb-00f3-4984b57bfac5¤codeÙSalmost(text) = Markdown.MD(Markdown.Admonition("warning", "Almost there!", [text]))¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$c5156c72-04af-11eb-1106-b13969b036ca„§cell_idÙ$c5156c72-04af-11eb-1106-b13969b036ca¤codeÚlet
run_basic_sir
N = 100
T = 1000
sim = simulation(N, T, InfectionRecovery(0.02, 0.002))
result = plot(1:T, sim.S, ylim=(0, N), label="Susceptible")
plot!(result, 1:T, sim.I, ylim=(0, N), label="Infectious")
plot!(result, 1:T, sim.R, ylim=(0, N), label="Recovered")
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$c4a8694a-04d4-11eb-1eef-c9e037e6b21f„§cell_idÙ$c4a8694a-04d4-11eb-1eef-c9e037e6b21f¤codeÚif !@isdefined(is_susceptible)
not_defined(:is_susceptible)
else
let
result1 = is_susceptible(Agent(I,2))
result2 = is_infected(Agent(I,2))
if result1 isa Missing || result2 isa Missing
still_missing()
elseif !(result1 isa Bool) || !(result2 isa Bool)
keep_working(md"Make sure that you return either `true` or `false`.")
elseif result1 === false && result2 === true
if is_susceptible(Agent(S,3)) && !is_infected(Agent(R,9))
correct()
else
keep_working()
end
else
keep_working()
end
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$1491a078-04aa-11eb-0106-19a3cf1e94b0„§cell_idÙ$1491a078-04aa-11eb-0106-19a3cf1e94b0¤codeÚ˜if !@isdefined(interact!)
not_defined(:interact!)
else
let
agent = Agent(I, 9)
source = Agent(S, 0)
interact!(agent, source, InfectionRecovery(1.0, 1.0))
if source.status != S || source.num_infected != 0
keep_working("The `source` should not be modified if `agent` is infectious.")
elseif agent.status != R
keep_working("The `agent` should recover from an infectious state with the right probability.")
elseif agent.num_infected != 9
keep_working(md"`agent.num_infected` should not be modified if `agent` is infectious.")
else
let
agent = Agent(I, 9)
source = Agent(R, 0)
interact!(agent, source, InfectionRecovery(1.0, 0.0))
if agent.status == R
keep_working("The `agent` should recover from an infectious state with the right probability.")
else
correct(md"Your function treats the **infectious** agent case correctly!")
end
end
end
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$c5c7cb86-041b-11eb-3360-45463105f3c9„§cell_idÙ$c5c7cb86-041b-11eb-3360-45463105f3c9¤codeÙ8# function do_experiment(p, N)
# return missing
# end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$01341648-0403-11eb-2212-db450c299f35„§cell_idÙ$01341648-0403-11eb-2212-db450c299f35¤code»md"_homework 4, version 0_"¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$d8797684-0414-11eb-1869-5b1e2c469011„§cell_idÙ$d8797684-0414-11eb-1869-5b1e2c469011¤codeÙ-function bernoulli(p::Number)
rand() < p
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$48a16c42-0414-11eb-0e0c-bf52bbb0f618„§cell_idÙ$48a16c42-0414-11eb-0e0c-bf52bbb0f618¤codeÙEhint(text) = Markdown.MD(Markdown.Admonition("hint", "Hint", [text]))¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$98beb336-0425-11eb-3886-4f8cfd210288„§cell_idÙ$98beb336-0425-11eb-3886-4f8cfd210288¤codeÙEfunction set_status!(agent::Agent, new_status::InfectionStatus)
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$bb63f3cc-042f-11eb-04ff-a128aec3c378„§cell_idÙ$bb63f3cc-042f-11eb-04ff-a128aec3c378¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$61c00724-0403-11eb-228d-17c11670e5d1„§cell_idÙ$61c00724-0403-11eb-228d-17c11670e5d1¤codeÚ¶md"""
## **Exercise 4:** _Reinfection_
In this exercise we will *re-use* our simulation infrastructure to study the dynamics of a different type of infection: there is no immunity, and hence no "recovery" rather, susceptible individuals may now be **re-infected**
#### Exercise 4.1
👉 Make a new infection type `Reinfection`. This has the *same* two fields as `InfectionRecovery` (`p_infection` and `p_recovery`). However, "recovery" now means "becomes susceptible again", instead of "moves to the `R` class.
This new type `Reinfection` should also be a **subtype** of `AbstractInfection`. This allows us to reuse our previous functions, which are defined for the abstract supertype.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$9cf9080a-04b1-11eb-12a0-17013f2d37f5„§cell_idÙ$9cf9080a-04b1-11eb-12a0-17013f2d37f5¤codeÚŒmd"""
👉 Calculate the **mean number of infectious agents** of our simulations for each time step. Add it to the plot using a heavier line (`lw=3` for "linewidth") by modifying the cell above.
Check the answer yourself: does your curve follow the average trend?
$(hint(md"This exercise requires some creative juggling with arrays, anonymous functions, `map`s, or whatever you see fit!"))
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8„§cell_idÙ$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8¤codeÙ[large_experiment = do_experiment(0.25, 10_000)
# (10_000 is just 10000 but easier to read)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$61789646-0403-11eb-0042-f3b8308f11ba„§cell_idÙ$61789646-0403-11eb-0042-f3b8308f11ba¤codeÚ.md"""
## **Exercise 2:** _Agent-based model for an epidemic outbreak -- types_
In this and the following exercises we will develop a simple stochastic model for combined infection and recovery in a population, which may exhibit an **epidemic outbreak** (i.e. a large spike in the number of infectious people).
The population is **well mixed**, i.e. everyone is in contact with everyone else.
[An example of this would be a small school or university in which people are
constantly moving around and interacting with each other.]
The model is an **individual-based** or **agent-based** model:
we explicitly keep track of each individual, or **agent**, in the population and their
infection status. For the moment we will not keep track of their position in space;
we will just assume that there is some mechanism, not included in the model, by which they interact with other individuals.
#### Exercise 2.1
Each agent will have its own **internal state**, modelling its infection status, namely "susceptible", "infectious" or "recovered". We would like to code these as values `S`, `I` and `R`, respectively. One way to do this is using an [**enumerated type**](https://en.wikipedia.org/wiki/Enumerated_type) or **enum**. Variables of this type can take only a pre-defined set of values; the Julia syntax is as follows:
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$39dffa3c-0414-11eb-0197-e72b299e9c63„§cell_idÙ$39dffa3c-0414-11eb-0197-e72b299e9c63¤codeÙ&bigbreak = html" ";¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$5950b37e-0a46-11eb-3480-d5520013692e„§cell_idÙ$5950b37e-0a46-11eb-3480-d5520013692e¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$cdaade9c-0416-11eb-0550-7b5b3d33e240„§cell_idÙ$cdaade9c-0416-11eb-0550-7b5b3d33e240¤codeÙGfunction do_experiment(p, N)
map(1:N) do _
recovery_time(p)
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$88c53208-041d-11eb-3b1e-31b57ba99f05„§cell_idÙ$88c53208-041d-11eb-3b1e-31b57ba99f05¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272„§cell_idÙ$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272¤codeÚif !@isdefined(interact!)
not_defined(:interact!)
else
let
agent = Agent(R, 9)
source = Agent(I, 0)
interact!(agent, source, InfectionRecovery(1.0, 1.0))
if source.status != I || source.num_infected != 0
keep_working(md"The `source` should not be modified if no infection occured.")
elseif agent.status != R || agent.num_infected != 9
keep_working(md"The `agent` should not be momdified if it is in a recoved state.")
else
correct(md"Your function treats the **recovered** agent case correctly!")
end
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$887d27fc-04bc-11eb-0ab9-eb95ef9607f8„§cell_idÙ$887d27fc-04bc-11eb-0ab9-eb95ef9607f8¤codeÙ~# function simulation(N::Integer, T::Integer, infection::AbstractInfection)
# return (S=missing, I=missing, R=missing)
# end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$d57c6a5a-041b-11eb-3ab4-774a2d45a891„§cell_idÙ$d57c6a5a-041b-11eb-3ab4-774a2d45a891¤codeÙß# function recovery_time(p)
# if p ≤ 0
# throw(ArgumentError("p must be positive: p = 0 cannot result in a recovery"))
# end
# # Your code here. See the comment below about the p ≤ 0 case.
# return missing
# end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$12cc2940-0403-11eb-19a7-bb570de58f6f„§cell_idÙ$12cc2940-0403-11eb-19a7-bb570de58f6f¤codeÙ/begin
using Pkg
Pkg.activate(mktempdir())
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$76f62d64-0403-11eb-27e2-3de58366b619„§cell_idÙ$76f62d64-0403-11eb-27e2-3de58366b619¤codeÙ md"""
#### Exercise 1.2
👉 Write a function `do_experiment(p, N)` that runs the function `recovery_time` `N` times and collects the results into a vector.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$860790fc-0403-11eb-2f2e-355f77dcc7af„§cell_idÙ$860790fc-0403-11eb-2f2e-355f77dcc7af¤codeÚmd"""
#### Exercise 2.2
For each agent we want to keep track of its infection status and the number of *other* agents that it infects during the simulation. A good solution for this is to define a *new type* `Agent` to hold all of the information for one agent, as follows:
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$b21475c6-04ac-11eb-1366-f3b5e967402d„§cell_idÙ$b21475c6-04ac-11eb-1366-f3b5e967402d¤codeÙÝmd"""
Play around with the test case below to test your function! Try changing the definitions of `agent`, `source` and `infection`. Since we are working with randomness, you might want to run the cell multiple times.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$823364ce-041c-11eb-2467-7ffa4f751527„§cell_idÙ$823364ce-041c-11eb-2467-7ffa4f751527¤codeÙ–function frequencies_plot_with_maximum(data::Vector)
base = bar(frequencies(data))
vline!(base, [maximum(data)], label="maximum")
return base
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$619c8a10-0403-11eb-2e89-8b0974fb01d0„§cell_idÙ$619c8a10-0403-11eb-2e89-8b0974fb01d0¤codeÚðmd"""
## **Exercise 3:** _Agent-based model for an epidemic outbreak -- Monte Carlo simulation_
In this exercise we will build on Exercise 2 to write a Monte Carlo simulation of how an infection propagates in a population.
Make sure to re-use the functions that we have already written, and introduce new ones if they are helpful! Short functions make it easier to understand what the function does and build up new functionality piece by piece.
You should not use any global variables inside the functions: Each function must accept as arguments all the information it requires to carry out its task. You need to think carefully about what the information each function requires.
#### Exercise 3.1
👉 Write a function `step!` that takes a vector of `Agent`s and an `infection` of type `InfectionRecovery`. It implements a single step of the infection dynamics as follows:
- Choose two random agents: an `agent` and a `source`.
- Apply `interact!(agent, source, infection)`.
- Return `agents`.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$38b1aa5a-04cf-11eb-11a2-930741fc9076„§cell_idÙ$38b1aa5a-04cf-11eb-11a2-930741fc9076¤codeÙ–function repeat_simulations(N, T, infection, num_simulations)
N = 100
T = 1000
map(1:num_simulations) do _
simulation(N, T, infection)
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$8dd97820-04a5-11eb-36c0-8f92d4b859a8„§cell_idÙ$8dd97820-04a5-11eb-36c0-8f92d4b859a8¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$df8547b4-0400-11eb-07c6-fb370b61c2b6„§cell_idÙ$df8547b4-0400-11eb-07c6-fb370b61c2b6¤codeÚÁmd"""
## **Exercise 1:** _Modelling recovery_
In this exercise we will investigate a simple stochastic (probabilistic) model of recovery from an infection and
the time $\tau$ needed to recover. Although this model can be easily studied analytically using probability theory, we will instead use computational methods. (If you know about this distribution already, try to ignore what you know about it!)
In this model, an individual who is infected has a constant probability $p$ to recover each day. If they recover on day $n$ then $\tau$ takes the value $n$. Each time we run a new experiment $\tau$ will take on different values, so $\tau$ is a (discrete) random variable. We thus need to study statistical properties of $\tau$, such as its mean and its probability distribution.
#### Exercise 1.1 - _Probability distributions_
👉 Define the function `bernoulli(p)`, which returns `true` with probability $p$ and `false` with probability $(1 - p)$.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$1d3356c4-0403-11eb-0f48-01b5eb14a585„§cell_idÙ$1d3356c4-0403-11eb-0f48-01b5eb14a585¤codeÙßhtml"""
VIDEO
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$82f2580a-04c8-11eb-1eea-bdb4e50eee3b„§cell_idÙ$82f2580a-04c8-11eb-1eea-bdb4e50eee3b¤code§Agent()¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$86d98d0a-0403-11eb-215b-c58ad721a90b„§cell_idÙ$86d98d0a-0403-11eb-215b-c58ad721a90b¤codeÚ,md"""
We will also need types representing different infections.
Let's define an (immutable) `struct` called `InfectionRecovery` with parameters `p_infection` and `p_recovery`. We will make it a subtype of an abstract `AbstractInfection` type, because we will define more infection types later.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$dc784864-0430-11eb-1478-d1153e017310„§cell_idÙ$dc784864-0430-11eb-1478-d1153e017310¤codeÙømd"""
The frequencies dictionary is difficult to interpret on its own, so instead, we will **plot** it, i.e. plot $P(\tau = n)$ against $n$, where $n$ is the recovery time.
Plots.jl comes with a function `bar`, which does exactly what we want:
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$3f5e0af8-0414-11eb-34a7-a71e7aaf6443„§cell_idÙ$3f5e0af8-0414-11eb-34a7-a71e7aaf6443¤codeÙÕyays = [md"Fantastic!", md"Splendid!", md"Great!", md"Yay â�¤", md"Great! 🎉", md"Well done!", md"Keep it up!", md"Good job!", md"Awesome!", md"You got the right answer!", md"Let's move on to the next section."]¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$3c0528a0-0414-11eb-2f68-a5657ab9e73d„§cell_idÙ$3c0528a0-0414-11eb-2f68-a5657ab9e73d¤codeÙ±not_defined(variable_name) = Markdown.MD(Markdown.Admonition("danger", "Oopsie!", [md"Make sure that you define a variable called **$(Markdown.Code(string(variable_name)))**"]))¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$7335de44-042f-11eb-2873-8bceef722432„§cell_idÙ$7335de44-042f-11eb-2873-8bceef722432¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$406aabea-04a5-11eb-06b8-312879457c42„§cell_idÙ$406aabea-04a5-11eb-06b8-312879457c42¤codeÙW# function interact!(agent::Agent, source::Agent, infection::InfectionRecovery)
# end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$c61f35ea-04d6-11eb-2503-17a79f8d0298„§cell_idÙ$c61f35ea-04d6-11eb-2503-17a79f8d0298¤codeÚ4if !@isdefined(recovery_time)
not_defined(:recovery_time)
else
let
result = recovery_time(1.0)
if result isa Missing
still_missing()
elseif !(result isa Integer)
keep_working(md"Make sure that you return an integer: the recovery time.")
else
if result == 1
samples = [recovery_time(0.2) for _ in 1:256]
a, b = extrema(samples)
if a == 1 && b > 20
correct()
else
keep_working()
end
else
keep_working(md"`p = 1.0` should return `1`: the agent recovers after the first time step.")
end
end
end
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$9cd2bb00-04b1-11eb-1d83-a703907141a7„§cell_idÙ$9cd2bb00-04b1-11eb-1d83-a703907141a7¤codeÙjlet
p = plot()
for sim in simulations
plot!(p, 1:1000, sim.I, alpha=.5, label=nothing)
end
p
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$8a28c56e-04b4-11eb-279c-3b4dfb2a9f9b„§cell_idÙ$8a28c56e-04b4-11eb-279c-3b4dfb2a9f9b¤codeÙ"bar(frequencies(large_experiment))¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$8631a536-0403-11eb-0379-bb2e56927727„§cell_idÙ$8631a536-0403-11eb-0379-bb2e56927727¤codeÚmd"""
#### Exercise 2.3
👉 Write functions `set_status!(a)` and `set_num_infected!(a)` which modify the respective fields of an `Agent`. Check that they work. [Note the bang ("`!`") at the end of the function names to signify that these functions *modify* their argument.]
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$9a13b17c-0403-11eb-024f-9b37e95e211b„§cell_idÙ$9a13b17c-0403-11eb-024f-9b37e95e211b¤codeÚŒmd"""
#### Exercise 4.2
👉 Run the simulation 20 times and plot $I$ as a function of time for each one, together with the mean over the 20 simulations (as you did in the previous exercises).
Note that you should be able to re-use the `sweep!` and `simulation` functions , since those should be sufficiently **generic** to work with the new `step!` function! (Modify them if they are not.)
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$b92f1cec-04ae-11eb-0072-3535d1118494„§cell_idÙ$b92f1cec-04ae-11eb-0072-3535d1118494¤codeÙ.simulation(3, 20, InfectionRecovery(0.9, 0.2))¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$5ef5813a-0a46-11eb-00d3-01ec142e3897„§cell_idÙ$5ef5813a-0a46-11eb-00d3-01ec142e3897¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$9a377b32-0403-11eb-2799-e7e59caa6a45„§cell_idÙ$9a377b32-0403-11eb-2799-e7e59caa6a45¤codeÙmd"""
👉 Run the new simulation and draw $I$ (averaged over runs) as a function of time. Is the behaviour qualitatively the same or different? Describe what you see.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$778ec25c-0403-11eb-3146-1d11c294bb1f„§cell_idÙ$778ec25c-0403-11eb-3146-1d11c294bb1f¤codeÙ”md"""
#### Exercise 1.5
👉 What shape does the distribution seem to have? Can you verify that by adding a second plot with the expected shape?
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$9611ca24-0403-11eb-3582-b7e3bb243e62„§cell_idÙ$9611ca24-0403-11eb-3582-b7e3bb243e62¤codeÙÊmd"""
#### Exercise 3.3
👉 Plot the probability distribution of `num_infected`. Does it have a recognisable shape? (Feel free to increase the number of agents in order to get better statistics.)
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$26f84600-041d-11eb-1856-b12a3e5c1dc7„§cell_idÙ$26f84600-041d-11eb-1856-b12a3e5c1dc7¤code»@enum InfectionStatus S I R¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$1ca7a8c2-041a-11eb-146a-15b8cdeaea72„§cell_idÙ$1ca7a8c2-041a-11eb-146a-15b8cdeaea72¤code½frequencies(small_experiment)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$190deebc-0424-11eb-19fe-615997093e14„§cell_idÙ$190deebc-0424-11eb-19fe-615997093e14¤codeÚ?md"""
👉 For convenience, define a new constructor (i.e. a new method for the function) that takes no arguments and creates an `Agent` with status `S` and number infected 0, by calling one of the default constructors that Julia creates. This new method lives *outside* (not inside) the definition of the `struct`. (It is called an **outer constructor**.)
(In Pluto, multiple methods for the same function need to be combined in a single cell using a `begin end` block.)
Let's check that the new method works correctly. How many methods does the constructor have now?
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$1a654bdc-0421-11eb-2c38-7d35060e2565„§cell_idÙ$1a654bdc-0421-11eb-2c38-7d35060e2565¤codeÙJstruct InfectionRecovery <: AbstractInfection
p_infection
p_recovery
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$41cefa68-0414-11eb-3bad-6530360d6f68„§cell_idÙ$41cefa68-0414-11eb-3bad-6530360d6f68¤codeÙ�keep_working(text=md"The answer is not quite right.") = Markdown.MD(Markdown.Admonition("danger", "Keep working on it!", [text]))¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$847d0fc2-041d-11eb-2864-79066e223b45„§cell_idÙ$847d0fc2-041d-11eb-2864-79066e223b45¤codeÙ€md"""
👉 Convert `x` to an integer using the `Integer` function. What value does it have? What values do `I` and `R` have?
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$77428072-0403-11eb-0068-81e3728f2ebe„§cell_idÙ$77428072-0403-11eb-0068-81e3728f2ebe¤codeÙ?md"""
Let's run an experiment with $p=0.25$ and $N=10,000$.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$9a837b52-0425-11eb-231f-a74405ff6e23„§cell_idÙ$9a837b52-0425-11eb-231f-a74405ff6e23¤codeÙ;function is_susceptible(agent::Agent)
return missing
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$0a967f38-0493-11eb-0624-77e40b24d757„§cell_idÙ$0a967f38-0493-11eb-0624-77e40b24d757¤codeÚ˜md"""
We used a `let` block in this cell to group multiple expressions together, but how is it different from `begin` or `function`?
$(html" ")
> ##### _**function**_ vs. _**begin**_ vs. _**let**_
> Writing functions is a way to group multiple expressions (i.e. lines of code) together into a mini-program. Note the following about functions:
> - A function always returns **one object**.[^1] This object can be given explicitly by writing `return x`, or implicitly: Julia functions always return the result of the last expression by default. So `f(x) = x+2` is the same as `f(x) = return x+2`.
> - Variables defined inside a function are _not accessible outside the function_. We say that function bodies have a **local scope**. This helps to keep your program easy to read and write: if you define a local variable, then you don't need to worry about it in the rest of the notebook.
>
> There are two other ways to group epxressions together that you might have seen before: `begin` and `let`.
>
> ###### begin
> **`begin`** will group expressions together, and it takes the value of its last subexpression.
>
> We use it in this notebook when we want multiple expressions to always run together.
>
> ###### let
> **`let`** also groups multiple expressions together into one, but variables defined inside of it are **local**: they don't affect code outside of the block. So like `begin`, it is just a block of code, but like `function`, it has a local variable scope.
>
> We use it when we want to define some local (temporary) variables to produce a complicated result, without interfering with other cells. Pluto allows only one definition per _global_ variable of the same name, but you can define _local_ variables with the same names whenever you wish!
>
> [^1]: Even a function like
>
> `f(x) = return`
>
> returns **one object**: the object `nothing` — try it out!
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$28db9d98-04ca-11eb-3606-9fb89fa62f36„§cell_idÙ$28db9d98-04ca-11eb-3606-9fb89fa62f36¤codeÙ3@bind run_basic_sir Button("Run simulation again!")¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$8692bf42-0403-11eb-191f-b7d08895274f„§cell_idÙ$8692bf42-0403-11eb-191f-b7d08895274f¤codeÙêmd"""
#### Exericse 2.4
👉 Write a function `generate_agents(N)` that returns a vector of `N` freshly created `Agent`s. They should all be initially susceptible, except one, chosen at random (i.e. uniformly), who is infectious.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$da49710e-0420-11eb-092e-4f1173868738„§cell_idÙ$da49710e-0420-11eb-092e-4f1173868738¤codeÚšmd"""
## **Exercise 5** - _Lecture transcript_
(MIT students only)
Please see the link for hw 4 transcript document on [Canvas](https://canvas.mit.edu/courses/5637).
We want each of you to correct about 400 lines, but don’t spend more than 15 minutes on it.
See the the beginning of the document for more instructions.
:point_right: Please mention the name of the video(s) and the line ranges you edited:
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$7bb8e426-0495-11eb-3a8b-cbbab61a1631„§cell_idÙ$7bb8e426-0495-11eb-3a8b-cbbab61a1631¤codeÙŠlet
expected_shape(x) = .25exp.(-.3(x))
p = bar(frequencies(large_experiment))
plot!(p, LinRange(0.0, 30.0, 100), expected_shape)
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$a4c9ccdc-12ca-11eb-072f-e34595520548„§cell_idÙ$a4c9ccdc-12ca-11eb-072f-e34595520548¤codeÚ«let
T = length(first(simulations).S)
all_S_counts = map(result -> result.S, simulations)
all_I_counts = map(result -> result.I, simulations)
all_R_counts = map(result -> result.R, simulations)
(S=round.(sum(all_S_counts) ./ length(simulations) ./ 100, digits=4),
I=round.(sum(all_I_counts) ./ length(simulations) ./ 100, digits=4),
R=round.(sum(all_R_counts) ./ length(simulations) ./ 100, digits=4))
end |> string¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$21c50840-0435-11eb-1307-7138ecde0691„§cell_idÙ$21c50840-0435-11eb-1307-7138ecde0691¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$2ade2694-0425-11eb-2fb2-390da43d9695„§cell_idÙ$2ade2694-0425-11eb-2fb2-390da43d9695¤codeÙM# function step!(agents::Vector{Agent}, infection::AbstractInfection)
# end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$aa6673d4-0417-11eb-32cc-79560896c195„§cell_idÙ$aa6673d4-0417-11eb-32cc-79560896c195¤codeÙ‚function frequencies(values)
result = Dict()
for x in values
result[x] = get(result, x, 0) + 1/length(values)
end
result
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$73047bba-0416-11eb-1047-23e9c3dbde05„§cell_idÙ$73047bba-0416-11eb-1047-23e9c3dbde05¤codeÙ4interpretation_of_p_equals_one = md"""
blablabla
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$bf6fd176-04cc-11eb-008a-2fb6ff70a9cb„§cell_idÙ$bf6fd176-04cc-11eb-008a-2fb6ff70a9cb¤codeÚ?md"""
#### Exercise 3.2
Alright! Every time that we run the simulation, we get slightly different results, because it is based on randomness. By running the simulation a number of times, you start to get an idea of the _mean behaviour_ of our model. This is the essence of a Monte Carlo method! You use computer-generated randomness to generate samples.
Instead of pressing the button many times, let's have the computer repeat the simulation. In the next cells, we run your simulation `num_simulations=20` times with $N=100$, $p_\text{infection} = 0.02$, $p_\text{infection} = 0.002$ and $T = 1000$.
Every single simulation returns a named tuple with the status counts, so the result of multiple simulations will be an array of those. Have a look inside the result, `simulations`, and make sure that its structure is clear.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$43e6e856-0414-11eb-19ca-07358aa8b667„§cell_idÙ$43e6e856-0414-11eb-19ca-07358aa8b667¤codeÙ€still_missing(text=md"Replace `missing` with your answer.") = Markdown.MD(Markdown.Admonition("warning", "Here we go!", [text]))¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$95c598d4-0403-11eb-2328-0175ed564915„§cell_idÙ$95c598d4-0403-11eb-2328-0175ed564915¤codeÙ�md"""
👉 Write a function `sir_mean_plot` that returns a plot of the means of $S$, $I$ and $R$ as a function of time on a single graph.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$2b26dc42-0403-11eb-205f-cd2c23d8cb03„§cell_idÙ$2b26dc42-0403-11eb-205f-cd2c23d8cb03¤code¨bigbreak¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$1ac4b33a-0435-11eb-36f8-8f3f81ae7844„§cell_idÙ$1ac4b33a-0435-11eb-36f8-8f3f81ae7844¤code ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$a8dd5cae-0425-11eb-119c-bfcbf832d695„§cell_idÙ$a8dd5cae-0425-11eb-119c-bfcbf832d695¤codeÙ8function is_infected(agent::Agent)
return missing
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_folded«notebook_idÙ$03ce5f0e-4aa7-11f0-2d78-7f415ce24d69«in_temp_dir¨metadata€